更改 TextInputEditText 提示颜色

Change TextInputEditText Hint Color

我想更改 TextInputEditText 提示的文本颜色。似乎无论我更改什么,颜色始终是主要应用程序主题的颜色。

            <android.support.design.widget.TextInputLayout
                android:id="@+id/enter_template_name_edit_text_input_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColorHint="@color/warm_grey">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/template_name_text_input_edit_text"
                    style="@style/EditTextBaseStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="start"
                    android:hint="@string/add_nitrogen_template_name_label"
                    android:imeOptions="actionNext"
                    android:inputType="textCapWords|textNoSuggestions"
                    android:maxLines="1"
                    android:paddingBottom="@dimen/md_content_padding_bottom"
                    android:textAlignment="textStart"
                    android:textColorHint="@color/warm_grey"
                    android:textSize="32sp" />

和基本样式

<style name="EditTextBaseStyle" parent="Widget.AppCompat.EditText">
    <item name="android:textViewStyle">@style/TextViewStyle</item>
    <item name="android:textColor">@color/middle_black</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textSize">16sp</item>
</style>

我试过添加

android:textColorHint="@color/warm_grey"

基本样式以及我的 AppTheme 都没有帮助。

这是我的 AppTheme

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/primary</item>
    <item name="android:textColorHint">@color/primary_text</item>
    <item name="android:windowBackground">@null</item>
    <item name="android:windowSoftInputMode">stateHidden|adjustPan</item>
</style>

我在这里遗漏了什么吗?

谢谢, 奥特曼

编辑:当字段 没有 具有焦点时提示是正确的颜色。当字段获得焦点时,提示会移动到字段上方并显示不正确的颜色。

您是否也为您的 AppTheme 尝试过这些属性?

<item name="colorControlNormal">@color/primary</item>
<item name="colorControlHighlight">@color/warm_grey</item>      
<item name="colorControlActivated">@color/warm_grey</item>

或移动

android:textColorHint="@color/warm_grey"

从 XML 小部件到 EditTextBaseStyle

试试这个:

 <style name="AppTheme.EditTextBaseStyle" parent="@android:style/TextAppearance">
    <item name="android:textColor">@android:color/darker_gray</item>
</style>

我能够通过添加

使其成功运行
app:hintTextAppearance="@style/EditTextHintStyle"

给我的TextInputLayout

这是正确的样式

<style name="EditTextHintStyle" parent="EditTextBaseStyle">
    <item name="android:textColor">@color/warm_grey</item>
</style>

我的解决方法是在 TextInputLayout 上设置提示和 textColor,而不是在 TextInputEditText 上设置,如下所述: https://material.io/develop/android/components/text-input-layout/

    <android.support.design.widget.TextInputLayout
        android:id="@+id/passwordTextInputLayout"
        android:hint="@string/add_nitrogen_template_name_label"
        android:textColorHint="@color/warm_grey">

        <android.support.design.widget.TextInputEditText
            android:textAppearance="@style/TextAppearance.Regular"
            android:textColor="@color/white"/>
    </android.support.design.widget.TextInputLayout>

您可以在布局中使用 app:hintTextColorandroid:textColorHint 属性:

<com.google.android.material.textfield.TextInputLayout
    app:hintTextColor="@color/mycolor"
    android:textColorHint="@color/text_input_hint_selector"
    .../>

或者您可以自定义样式来定义它们:

<style name="..." parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
    <!-- The color of the label when it is collapsed and the text field is active -->
    <item name="hintTextColor">@color/my_color</item>

    <!-- The color of the label in all other text field states (such as resting and disabled) -->
    <item name="android:textColorHint">@color/my_selector_color</item>
</style>