TextInputLayout使错误消息和提示颜色不同

时间:2019-07-14 18:42:55

标签: android android-textinputlayout

How to style com.google.android.material.textfield.TextInputLayout such that error message and hint colour,by default both colors are same red ,can be changed.I tried below code,but both error message and hint colour change

以下是app:errorTextAppearance的样式

<style name="TextErrorAppearanceError" parent="TextAppearance.Design.Error">
    <!-- Error message appearance here -->
   <item name="android:colorError">@color/color3</item>
    <item name="android:textSize">12sp</item>

    <item name="android:textColor">@color/color2</item>
    <item name="android:fontFamily">@font/fontfamily</item>
</style>

还在将错误设置为textInputLayout之前尝试了以下代码 edTextEdit.setHintTextColor(resources.getColor(android.R.color.holo_green_dark))

1 个答案:

答案 0 :(得分:0)

styles.xml

<style name="error_appearance" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/colorCoralPink</item>
        <item name="android:textSize">12sp</item>
    </style>

在您的TextInputLayout中进行

 app:errorTextAppearance="@style/error_appearance"

希望这会有所帮助。