How to Set Textinputlayout Error Message Colour

How to set TextInputLayout error message colour?

Create a custom style which uses @android:style/TextAppearance as parent in your styles.xml file:

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

And use it in your TextInputLayout widget:

 <android.support.design.widget.TextInputLayout
android:id="@+id/emailInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorTextAppearance="@style/error_appearance">

error example

Edit: Set the hint on the object, which is inside your TextInputLayout (EditText, TextView, etc.) to hold different colors for the hint and the error.

How to change underline color error textinputlayout android

Just use the app:boxStrokeErrorColor attribute:

    <com.google.android.material.textfield.TextInputLayout
app:boxStrokeErrorColor="@color/primaryLightColor"
...>

Sample Image

It requires Material Components lirabry version 1.2.0.

TextInputLayout default error color on Android

The only solution I found was to check the code of TextInputLayout.
I found that the style is

<style name="TextAppearance.Design.Error" parent="TextAppearance.AppCompat.Caption">
<item name="android:textColor">@color/design_textinput_error_color</item>
</style>

where

<color name="design_textinput_error_color">#FFDD2C00</color>

but it seems this is not documented so it can change

How to know what is color of TextInputLayout error in Android?

The default error color is based on the colorError attribute.

The current value in a light theme is:

<color name="design_default_color_error">#B00020</color>

If you want to use it in another attribute you can copy this value or you can use ?attr/colorError. Example:

<item name="strokeColor">?attr/colorError</item>

If you want to get programmatically this value you can use:

MaterialColors.getColor(fab, R.attr.colorError)


Related Topics



Leave a reply



Submit