Robert Höglund
Robert Höglund

Reputation: 10090

How to change the text color of the error popup for an EditText?

On ICS, when using a theme based upon android:Theme.Light the text in the error popup when using setError(...) is white, as is the background.

I can fix this issue by adding <item name="android:textColorPrimaryInverse">#ff000000</item> to my theme. While this helps I'm a bit worried that by doing that change some other text, that uses textColorPrimaryInverse will turn from white to black and perhaps not be visible. I would rather just change that attribute for the EditText that displays the popup in question or for just that activity.

Clarification

I would like to change a property, preferably the text color, of the popup that displays the error message when the user enters something wrong into an EditText.

Upvotes: 8

Views: 3068

Answers (2)

mostar
mostar

Reputation: 4841

You can do it like this:

editText.setError(Html.fromHtml("<font color='red'>Error Message!</font>"));

Upvotes: 1

Gangnus
Gangnus

Reputation: 24484

In code use http://developer.android.com/reference/android/view/View.html#setBackgroundResource(int) or http://developer.android.com/reference/android/view/View.html#setBackgroundColor(int). They belong to View, but EditText inherits them. The second methiod is easier, the first is more consistant.

Edit: Oh, it is a more hard question. Maybe, using EditText.setError(CharSequence error, Drawable icon) you can put error text on the icon? You can set setBounds(Rect) for the icon, so, it could be enough big. The icon can be the color you need.

But I use onKey,beforeTextChanged, onTextChanged and show my own error message as a Toast. For the toast you can use an usual View.

Upvotes: 0

Related Questions