What I want to do is change the background color (set custom drawable) of a popup error message displayed after using setError()
method.
Currently, it looks like this:
I've found that Android has two files:
popup_inline_error.9.png
popup_inline_above_error.9.png
And you're supposed to be able to set them using two attributes:
errorMessageBackground
errorMessageAboveBackground
But when I try to set them in my theme, all I get is:
<item name="errorMessageBackground">@drawable/popup_inline_error_holo_light</item>
<item name="errorMessageAboveBackground">@drawable/popup_inline_error_above_holo_light</item>
error: Error: No resource found that matches the given name: attr 'errorMessageBackground'.
(it's the same with android:errorMessageBackground
)
I'm putting this question here, cause I've run out of ideas - maybe someone already managed to do that?
EDIT: Header of the Theme I'm using:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style
name="Theme.MyThemeName"
parent="@style/Theme.Sherlock.Light">
ANOTHER EDIT: Uh, I've found that my question is a duplicate of: android:errorMessageBackground getting no resource found error in styles.xml
YET ANOTHER EDIT: This is a known problem, take a look at this link: https://code.google.com/p/android/issues/detail?id=55879
You can use this method just pass msg text,your edittext id
I would suggest to use @Codeversed solution, but if it doesn't fit for you for some reason you can use my custom
EditText
implementation.Usual EditText representation:
EditText with error:
In few words: I've created custom xml state for error display. See related code below:
InputEditText.java:
drawable/edittext_bg_error.xml
drawable/edittext_bg_selector.xml
add to your attrs.xml
and to styleables.xml
and usage is really simple:
[EDIT]:
Just realized, that original answer was about changing error popup color, but not EditText background color. Anyway, hope this can help someone.
you will need to include these dependancies:
and here is a sample on how to use it:
This will give you the Material Design you are looking for to give form validation as well as a nice animation effect for the label.