Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:TextInputLayout-自定义提示、底线和错误消息的颜色_Android_Xml_Android Layout_Android Design Library_Android Textinputlayout - Fatal编程技术网

Android:TextInputLayout-自定义提示、底线和错误消息的颜色

Android:TextInputLayout-自定义提示、底线和错误消息的颜色,android,xml,android-layout,android-design-library,android-textinputlayout,Android,Xml,Android Layout,Android Design Library,Android Textinputlayout,我的布局如下所示: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <com.google.android.material.textfield.TextInputLayout android:id="@+id/email_container

我的布局如下所示:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/email_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="E-mail"
            android:imeOptions="actionDone"
            android:inputType="textEmailAddress"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
结果是:

正如您所看到的,提示底线错误消息都是红色的

我的目标

<style name="TextInputCustonColor" 
  parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
    <!-- The color of the label  -->
    <item name="android:textColorHint">@color/colorPrimaryGolden</item>
    <!-- The color of the label -->
    <item name="android:colorError" tools:targetApi="o">@color/colorError</item>
    <!--the color of text-->
    <item name="android:textColor">@color/colorPrimaryGolden</item>
    <!--the color of background-->
    <item name="boxBackgroundColor">@android:color/transparent</item>

</style>
为提示使用单独的颜色。那就是。。。在底线和消息上保持红色,但在错误状态下使用另一种颜色作为提示


已尝试:

…以及其他解决方案,试图解决当
android.support.design.widget.TextInputLayout
包装一个简单的
EditText
时出现的问题

但是,在我的例子中,我使用的是
com.google.android.material.textfield.TextInputLayout
com.google.android.material.textfield.textinputtext

设置错误后,我还尝试调用
setErrorTextColor
setDefaultHintTextColor

email_container.setError("You must fill this field!");
email_container.setErrorTextColor(new ColorStateList(states, colors));
email_container.setDefaultHintTextColor(new ColorStateList(statesHint, colorsHint));

// Also tried with other states, but nothing
int[][] states = new int[][] {
        new int[] { android.R.attr.state_enabled},
        new int[] {-android.R.attr.state_enabled},
};

int[][] statesHint = new int[][] {
        new int[] { android.R.attr.state_enabled},
        new int[] {-android.R.attr.state_enabled},
};


int[] colors = new int[] {
        R.color.yellow,
        R.color.green,
};


int[] colorsHint = new int[] {
        R.color.black90,
        R.color.bt_text_blue,
};
但是我得到的唯一结果是,结合不同的状态,使消息的颜色不同,但是提示底线仍然具有相同的颜色


有人知道如何处理这个问题吗?

我们可以自定义样式来自定义文本输入版面颜色。尝试此代码根据需要更改TextInputLayout颜色代码

style.xml

<style name="TextInputCustonColor" 
  parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
    <!-- The color of the label  -->
    <item name="android:textColorHint">@color/colorPrimaryGolden</item>
    <!-- The color of the label -->
    <item name="android:colorError" tools:targetApi="o">@color/colorError</item>
    <!--the color of text-->
    <item name="android:textColor">@color/colorPrimaryGolden</item>
    <!--the color of background-->
    <item name="boxBackgroundColor">@android:color/transparent</item>

</style>

@颜色/原色金色
@颜色/颜色错误
@颜色/原色金色
@android:彩色/透明
activity.xml

    <android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:errorEnabled="true"
    style="@style/TextInputCustonColor">

    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        style="@style/TextInputCustonColor"
        android:imeOptions="actionDone"
        android:inputType="textEmailAddress"
        android:maxLines="1" />

</android.support.design.widget.TextInputLayout>