【问题标题】:How to style hintTextColor of TextInputLayout in a theme?如何在主题中设置 TextInputLayout 的hintTextColor 样式?
【发布时间】:2021-03-20 08:16:52
【问题描述】:

应用使用以下 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 没有影响。

有人能解释一下吗?

【问题讨论】:

    标签: android material-design material-components-android android-textinputlayout mdc-components


    【解决方案1】:

    你可以使用:

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

    【讨论】:

    • 谢谢。以我目前对 MDC 的了解,我永远无法弄清楚。
    猜你喜欢
    • 2019-07-30
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多