u3l
u3l

Reputation: 3412

Can EditText's error message icon be changed?

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?

Upvotes: 0

Views: 895

Answers (3)

Ahad Khan
Ahad Khan

Reputation: 271

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);

Upvotes: 0

Apoorv
Apoorv

Reputation: 13520

You can use

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

where iconDrawable is a Drawable

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157437

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

Upvotes: 2

Related Questions