更改TextInputEditText提示颜色

Ott*_*man 6 android android-layout android-textinputlayout

我想更改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" />
Run Code Online (Sandbox Code Playgroud)

和基本风格

<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>
Run Code Online (Sandbox Code Playgroud)

我试过添加

android:textColorHint="@color/warm_grey"
Run Code Online (Sandbox Code Playgroud)

对基本风格以及我的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>
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?

谢谢,奥特曼

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

ahe*_*ann 13

对我来说,修复是在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>
Run Code Online (Sandbox Code Playgroud)


Gab*_*tti 6

您可以在布局中使用app:hintTextColor和属性:android:textColorHint

<com.google.android.material.textfield.TextInputLayout
    app:hintTextColor="@color/mycolor"
    android:textColorHint="@color/text_input_hint_selector"
    .../>
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)


sna*_*msm 5

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

<item name="colorControlNormal">@color/primary</item>
<item name="colorControlHighlight">@color/warm_grey</item>      
<item name="colorControlActivated">@color/warm_grey</item>
Run Code Online (Sandbox Code Playgroud)

或移动

android:textColorHint="@color/warm_grey"
Run Code Online (Sandbox Code Playgroud)

从 XML 小部件到 EditTextBaseStyle