TextInputLayout - setError不会将浮动提示颜色更改为错误颜色

时间:2018-06-14 12:34:30

标签: android android-styles android-textinputlayout android-textinputedittext

我遇到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" />

styles.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);

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

$(document).ready(function () {
})   // inside this you need to write 

1. ## If drop down list ##
$('#serviceType').on('change', function () {
            if ($('#serviceType').text() != '') {
                $('#Error-ServiceType').hide();
            }
        });

2. ## If text box ##
$('#rateperhr').on('keyup keypress change', function () {
            if ($('#rateperhr').val() != '') {
                $('#Err_rateperhour').hide();
            }
        });