0

In EditText, errors can be set programmatically like this:

if(TextUtils.isEmpty(nameEditText.getText()))
     nameEditText.setError(getString("This field is required"));

And as a result, this would show up:

enter image description here

Is there any way to change the error icon to an image or drawable?

Kailas
  • 7,350
  • 3
  • 47
  • 63
u3l
  • 3,342
  • 4
  • 34
  • 51
  • this post may help you http://stackoverflow.com/questions/8985295/edittext-seterror-with-icon-but-without-popup-message – Giru Bhai Jun 05 '14 at 08:29

3 Answers3

2

you can use setError(CharSequence, Drawable). Here the documentation

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
1

You can use

if(TextUtils.isEmpty(nameEditText.getText()))
 nameEditText.setError(getString("This field is required"),iconDrawable);

where iconDrawable is a Drawable

Apoorv
  • 13,470
  • 4
  • 27
  • 33
0
Drawable icon = 
getResources().getDrawable(R.drawable.ic_error_icon);
if (icon != null) {
icon.setBounds(0, 0, 
             icon.getIntrinsicWidth(),
             icon.getIntrinsicHeight());
}
editText.setError(“Error test”, icon);
Ahad Khan
  • 271
  • 3
  • 4