如何在主题中设置 TextInputLayout 的 hintTextColor 样式?

How to style hintTextColor of TextInputLayout in a theme?

一个应用为其主题使用了以下 MyThemeStyle:

<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>

在 AndroidManifest 中:

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

这适用于 EditText,但对 com.google.android.material.textfield.TextInputLayout 没有影响。

有人能解释一下吗?

您可以使用:

<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>