java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 In TextInputLayout(示例代
Posted 天长地久-无为
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 In TextInputLayout(示例代相关的知识,希望对你有一定的参考价值。
when we use TextInputLayout to set
setErrorEnabled(true)
it throws exception thus:
09-26 17:46:04.650 19427-19427/com.ifreecomm.mst E/AppCompatResources: Failed to inflate ColorStateList, leaving it to the framework java.lang.UnsupportedOperationException: Can‘t convert to color: type=0x2 at android.content.res.TypedArray.getColor(TypedArray.java:327) at android.support.v7.content.res.AppCompatColorStateListInflater.inflate(AppCompatColorStateListInflater.java:114) at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXmlInner(AppCompatColorStateListInflater.java:88) at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXml(AppCompatColorStateListInflater.java:67) at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:116) at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:74) at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:136) at android.support.v7.widget.AppCompatTextHelper.onSetTextAppearance(AppCompatTextHelper.java:157) at android.support.v7.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:148) at android.support.v4.widget.TextViewCompatGingerbread.setTextAppearance(TextViewCompatGingerbread.java:103) at android.support.v4.widget.TextViewCompat$BaseTextViewCompatImpl.setTextAppearance(TextViewCompat.java:86) at android.support.v4.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:283) at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:609) at com.mst.v2.dialog.LoginDialog.onDataChangeListener(LoginDialog.java:288) at com.mst.v2.app.AppContext$1.handleMessage(AppContext.java:85) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5111) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) at dalvik.system.NativeStart.main(Native Method)
the solution is adding
app:errorTextAppearance="@style/ErrorText"
in the TextInputLayout‘s xml.
ErrorText.xml :
<style name="ErrorText"> <item name="android:textColor">@color/red</item> <item name="android:textSize">12sp</item> </style>
以上是关于java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 In TextInputLayout(示例代的主要内容,如果未能解决你的问题,请参考以下文章