How to change background color Edittext error box

34 Views Asked by At

enter image description here

I can't change background color of error text box color.

Want to change the background color of error box not text color. The way i tried to set setErrorTextColor, setErrorColor, setBackGroundColor not defined.

2

There are 2 best solutions below

0
dennisrufigill On

You can change the color of the error block of editText by using the following code.

yourEditText.setErrorColor(Color.parseColor("Pass Your Color Code"));
0
Da Chelimo On

I would recommend you switch to Material.io TextInputLayout which not only provides a smoother error handling API but also has more customization features

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label">

<com.google.android.material.textfield.TextInputEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

</com.google.android.material.textfield.TextInputLayout>

For an in-depth documentation of all the features that come with Material.io version of Edittext, go to Material.io Text Field - Android