Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout default error color on Android

Tags:

android

Since it is not easy to customize the color of the error in a TextInputLayout, I decided to change my error colour to match the one used by default by TextInputLayout.

In the design guidelines I could not find the definition of the default colour.

Do you know where I can find it?

like image 855
kingston Avatar asked Mar 26 '16 15:03

kingston


People also ask

What is TextInputLayout in Android?

TextInputLayout is a view container that is used to add more features to an EditText. It acts as a wrapper for EditText and has some features like: Floating hint. Animation that can be disabled or enabled. Error labels that display error messages when an error occurs.

Why use TextInputLayout?

The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.


2 Answers

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

like image 112
kingston Avatar answered Oct 21 '22 00:10

kingston


Update in 2020.

TextInputLayout error color can be acquired via:

ContextCompat.getColor(this, com.google.android.material.R.color.design_error)

But it is marked private and can be changed. Approximately color value is:

<color name="color_text_input_error_color">#E87850</color>
like image 37
Levor Avatar answered Oct 21 '22 01:10

Levor