我遇到了 TextInputLayout 错误状态的问题。当我在 TextInputLayout 上设置错误时,错误消息是红色的,还有下划线,但提示没有(它保持默认颜色 - 灰色)。我已经设置了errorTextAppearance,但我似乎无法让提示文本改变颜色。
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="My Hint"
app:errorTextAppearance="@style/MyErrorTextAppearance">
<android.support.design.widget.TextInputEditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLength="10"
android:maxLines="1" />
样式.xml
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MyErrorTextAppearance" parent="TextAppearance.Design.Error">
<item name="android:textColor">@color/colorError</item>
</style>
我设置并清除错误如下:
myTextInputLayout.setErrorEnabled(true);
myTextInputLayout.setError(errorMessage);
myTextInputLayout.setError(null);
myTextInputLayout.setErrorEnabled(false);