How to write style to error text of EditText in android?

The solution is at the end and here is the screenshot:

Styled error


Some Explanation

You might be able to set the textcolor using the following line

yourEditText.setError(Html.fromHtml("<font color="blue">this is the error</font>"));

However, this might not be guaranteed.


According to the source code, this Popup that shows is of type ErrorPopup which is an internal class inside TextView. The content of this Popup is a single TextView inflated from com.android.internal.R.layout.textview_hint

final TextView err = (TextView) inflater.inflate(com.android.internal.R.layout.textview_hint,
      null);

The background of this Popup depends on whether it should be placed above the anchor:

if (above) {
    mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error_above);
} else {
    mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error);
}

Since all the android resources used to create the popup are internal and ultimately hard-coded, your best shot would be to create your own error popup. This would be very easy and you wouldn’t really be interfering with the normal EditText because the default popup is merely used to show the error, and, thus, creating your own would be fine.


SOLUTION

I have created it here: WidgyWidgets

Leave a Comment