Reputation: 3412
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:
Is there any way to change the error icon to an image or drawable
?
Upvotes: 0
Views: 895
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
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