Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to inflate ColorStateList, leaving it to the framework java.lang.UnsupportedOperationException: Can't convert to color: type=0x2

Tags:

android

xml

I have a login part and I use TextInputLayout for email and password. Both of them are the same. Also I use Data binding to show the Error message.

The error is happening on API < 20 when it should show an Error Hint.

    @Override
    public void showEmailError() {
        inputLayoutEmail.setError(sInvalidEmail);
    }

xml layout :

        <android.support.design.widget.TextInputLayout
            android:id="@+id/til_email"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginLeft="@dimen/default_margin_16dp"
            android:layout_marginRight="@dimen/default_margin_16dp"
            android:layout_marginTop="16dp"
            android:layout_below="@id/login_img_logo"
            android:layout_centerHorizontal="true"
            android:textColorHint="@color/gray"
            android:background="@drawable/login_edittext"
            android:errorEnabled="@{viewmodel.obEmailErrorVisibility}"
            >

            <EditText
                android:id="@+id/et_login"
                android:layout_height="@dimen/login_view_height"
                android:layout_width="@dimen/login_view_width"
                android:inputType="text"
                android:maxLength="50"
                android:hint="@string/activity_login_hint_email"
                android:text="@={viewmodel.email}"
                android:textColor="@color/black"
                android:textColorHint="@color/gray"
                android:paddingLeft="@dimen/default_margin_16dp"
                android:enabled="@{viewmodel.obIsEmailFieldEnabled}"
                />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/til_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/default_margin_16dp"
            android:layout_marginRight="@dimen/default_margin_16dp"
            android:layout_marginTop="@dimen/default_margin_8dp"
            android:layout_below="@id/til_email"
            android:layout_centerHorizontal="true"
            android:textColorHint="@color/gray"
            android:background="@drawable/login_edittext"
            android:errorEnabled="@{viewmodel.obPassErrorVisibility}"
            >

            <EditText
                android:id="@+id/et_password"
                android:layout_width="@dimen/login_view_width"
                android:layout_height="@dimen/login_view_height"
                android:hint="@string/activity_login_hint_password"
                android:maxLength="50"
                android:inputType="textPassword"
                android:text="@={viewmodel.password}"
                android:textColor="@color/black"
                android:textColorHint="@color/gray"
                android:paddingLeft="@dimen/default_margin_16dp"
                android:enabled="@{viewmodel.obIsPassFieldEnabled}"
                />

        </android.support.design.widget.TextInputLayout>

as background I use login_edittext.xml

<solid android:color="@color/white" />

<corners
    android:radius="@dimen/login_edittext_radius"
    />

I have check similar answers, but most of them are related to styles

Can't convert to color: type=0x2 error when inflating layout in fragment but only on Samsung Galaxy and Note 4

like image 454
aleksandrbel Avatar asked Jun 22 '17 06:06

aleksandrbel


1 Answers

So, I have finished with this solution that works for me.

To TextInputLayout add this string

app:errorTextAppearance="@style/MyAppTheme.TextInputLayout"

And add new style to styles.xml

    <style name="MyAppTheme.TextInputLayout" parent="@android:style/TextAppearance">
         <item name="android:textColor">@color/red</item>
    </style>
like image 197
aleksandrbel Avatar answered Nov 18 '22 04:11

aleksandrbel