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>

 

posted @ 2017-09-30 17:27  天长地久-无为  阅读(1565)  评论(0编辑  收藏  举报