I want to set a setError
method to my TextView
, with a custom icon instead of the default Android icon. So I tried this:
((EditText
Drawable customErrorDrawable = getResources().getDrawable(R.drawable.error_icon);
customErrorDrawable.setBounds(0, 0, customErrorDrawable.getIntrinsicWidth(), customErrorDrawable.getIntrinsicHeight());
editText.setError("please enter data",customErrorDrawable);
If you don't want to show any icon at all, use
editText.setError("error", null);
You need to set the bounds on the drawable before using it in setError.
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
editText.setError("error", drawable);
This issue is discussed and resolved here:
EditText setError() with icon but without Popup message
I hope that by extending the answer it would not get auto-converted to a comment.