8

我正在尝试使用 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)
4

1 回答 1

10

TextInputLayout使用, 和设置时我遇到了同样的错误errorEnabled

textColorError我通过向我的自定义 App 主题添加一个来解决它:

<style name="YOURCUSTOMTHEME" parent="YOUR.PARENT.THEME">
     <!-- ..... other styles -->
     <item name="textColorError">@color/YOUR_COLOR</item>
</style>
于 2017-11-19T14:21:09.080 回答