I have a very simple EditText, as follows:
<EditText
android:id="@+id/myedit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLength="32"/>
In some validation code, I use Android's EditText.setError()
to show any validation errors. This works fine in OS 2.x but not on an OS 3.x device (Xoom) -- on the Xoom you can see the outline of the error popup but you cannot see the error text.
I'm guessing that the text is there, but it is invisible. How do I make it visible? I don't see an android:textColor
that would relate to error text.
Also, if the text is indeed invisible, then any ideas why 2.x behaves differently to 3.x -- seems like this would cause backward-compatibility problems.
Thanks.
It looks like you can work around this problem by calling EditText.setError() with a SpannableStringBuilder object rather than a String.
int ecolor = xxxx; // whatever color you want
String estring = "Input is incorrect";
ForegroundColorSpan fgcspan = new ForegroundColorSpan(ecolor);
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(estring);
ssbuilder.setSpan(fgcspan, 0, estring.length(), 0);
myedittext.setError(ssbuilder);
For a more elegant solution try this one:
editText.setError(Html.fromHtml("<font color='red'>Error Message!</font>"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With