无法在TextInputLayout上膨胀ColorStateList

时间:2017-06-22 07:33:08

标签: android android-textinputlayout textinputlayout

我尝试使用TextInputLayouts创建登录屏幕。但我无法显示错误。我在LogCat上收到了下一个错误,并且没有出现错误。

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

我有一些下一个组件。

<android.support.design.widget.TextInputLayout
            android:id="@+id/til_email"
            android:layout_width="match_parent"
            android:layout_height="@dimen/textinput_height">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/et_email"
                android:layout_width="match_parent"
                android:layout_height="@dimen/textinput_height"
                android:drawableLeft="@drawable/ic_face"
                android:drawableStart="@drawable/ic_face"
                android:drawablePadding="8dp"
                android:hint="@string/str_email"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"
                android:textColor="@color/blue"
                android:typeface="normal" />
        </android.support.design.widget.TextInputLayout>

我不知道如何解决这个失败。有人可以告诉我一些建议吗?

谢谢。

堆栈跟踪

06-22 09:26:46.897 1853-1853/com.ikomobi.SuscribeApp 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:326)
                                                                               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.ikomobi.SuscribeApp.ui.login.LoginFragment.setUp(LoginFragment.java:81)
                                                                               at com.ikomobi.SuscribeApp.ui.login.LoginFragment.onCreateView(LoginFragment.java:73)
                                                                               at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                               at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                               at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                               at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                               at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                               at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                               at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                                                                               at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                                                                               at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                                                                               at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
                                                                               at android.app.Activity.performStart(Activity.java:5018)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                                                                               at android.app.ActivityThread.access$600(ActivityThread.java:130)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                               at android.os.Looper.loop(Looper.java:137)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                               at java.lang.reflect.Method.invokeNative(Native Method)
                                                                               at java.lang.reflect.Method.invoke(Method.java:511)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                               at dalvik.system.NativeStart.main(Native Method)
06-22 09:26:46.897 1853-1853/com.ikomobi.SuscribeApp 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:326)
                                                                               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.ikomobi.SuscribeApp.ui.login.LoginFragment.setUp(LoginFragment.java:82)
                                                                               at com.ikomobi.SuscribeApp.ui.login.LoginFragment.onCreateView(LoginFragment.java:73)
                                                                               at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                               at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                               at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                               at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                               at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                               at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                               at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                                                                               at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                                                                               at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                                                                               at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
                                                                               at android.app.Activity.performStart(Activity.java:5018)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                                                                               at android.app.ActivityThread.access$600(ActivityThread.java:130)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                               at android.os.Looper.loop(Looper.java:137)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                               at java.lang.reflect.Method.invokeNative(Native Method)
                                                                               at java.lang.reflect.Method.invoke(Method.java:511)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                               at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:11)

使用TextInputLayout并设置errorEnabled

时出现同样的错误

我通过在我的自定义应用主题中添加textColorError来解决这个问题:

<style name="YOURCUSTOMTHEME" parent="YOUR.PARENT.THEME">
     <!-- ..... other styles -->
     <item name="textColorError">@color/YOUR_COLOR</item>
</style>