Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change error background of TextInputLayoutText error when using a border?

Tags:

android

I'm using Android Design Library's TextInputLayout and TextInputEditText with a background. When setting an error, the field is highlighted with a rather jarring red background that my client dislikes.

I can style away the red background if I don't include the field border, but not if I use one. I've tried all the styling options that I've seen in the relevant S/O answers with no success.

I also tried setting the background in code after setting the error as described in the top answer here, and the red background is temporarily removed from the input field, but reappears as soon as the field is reentered. I tried adding a focus change listener and redoing the setBackgroundResource call, but I still get the red background. Stepping through with a debugger shows that there is a frame choreographer message posted that eventually adds the background color back. Since this approach always felt like a work-around, I haven't tried to post my own messages to set it back.

It appears to me that my desired background resource is being replaced by a background color one. Is there a way to style that away that I'm just not seeing? enter image description here enter image description here

like image 239
scottt Avatar asked Dec 03 '25 04:12

scottt


1 Answers

i've managed to do it by putting transparent background like this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_focused="true"
        android:top="5dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="1dp"
                android:color="@color/colorWhite" />
            <corners android:radius="50dp" />
            <padding
                android:bottom="13dp"
                android:left="13dp"
                android:right="13dp"
                android:top="13dp" />
        </shape>
    </item>
</layer-list>
like image 163
Achmad Naufal Syafiq Avatar answered Dec 05 '25 17:12

Achmad Naufal Syafiq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!