Search code examples
androidmaterial-designmaterial-components-androidandroid-textinputlayoutmdc-components

How to style hintTextColor of TextInputLayout in a theme?


An app uses the following MyThemeStyle for its theme:

<style name="MyThemeStyle" parent="@style/Theme.MaterialComponents">
    <item name="hintTextAppearance">@style/HintText</item>
    <item name="hintTextColor">@color/red</item>
</style>
<style name="HintText" parent="TextAppearance.AppCompat">
    <item name="android:textColor">@color/red</item>
</style>

In AndroidManifest:

<application
    android:theme="@style/MyThemeStyle">

This works for EditText, but has no effect on com.google.android.material.textfield.TextInputLayout.

Could anyone shed some light on this?


Solution

  • You can use:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light">
      <item name="textInputStyle">@style/TextInput</item>
    </style>
    
    <style name="TextInput" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
       <item name="hintTextAppearance">@style/....</item>
       <!-- The color of the label when it is collapsed and the text field is active -->
       <item name="hintTextColor">?attr/colorPrimary</item>
    
       <!-- The color of the label in all other text field states (such as resting and disabled) -->
       <item name="android:textColorHint">@color/mtrl_indicator_text_color</item>
    </style>