本文介绍了无法使ColorStateList膨胀,将其留给框架java.lang.UnsupportedOperationException:无法转换为颜色:type = 0x2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个登录部分,我使用TextInputLayout作为电子邮件和密码.他们都是一样的.另外,我使用数据绑定来显示错误消息.
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.
API<上发生错误.20,它应该显示错误提示.
The error is happening on API < 20 when it should show an Error Hint.
@Override
public void showEmailError() {
inputLayoutEmail.setError(sInvalidEmail);
}
xml布局:
<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>
我使用的背景 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
可以't转换为颜色:放大片段中的布局时会出现type = 0x2错误,但仅限于Samsung Galaxy和Note 4
推荐答案
因此,我已经完成了适用于我的解决方案.
So, I have finished with this solution that works for me.
向 TextInputLayout 添加此字符串
app:errorTextAppearance="@style/MyAppTheme.TextInputLayout"
并将新样式添加到 styles.xml
<style name="MyAppTheme.TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/red</item>
</style>
这篇关于无法使ColorStateList膨胀,将其留给框架java.lang.UnsupportedOperationException:无法转换为颜色:type = 0x2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!