0

By default, the setError makes an EditText look like the following:

setError view

There's a red exclamation. The error message pops-up when that particular EditText gains focus.

I'm creating a custom setError method:

validatedIcon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.validated);
validatedIcon.setBounds(0, 0, validatedIcon.getIntrinsicWidth(), validatedIcon.getIntrinsicHeight());
firstName.setError("Please check your first name",validatedIcon);

My new error icon is a custom icon. But I don't want the error message to be displayed with it. I tried passing null as the message, but that removed the whole icon. I tried passing the empty string, but that simply made an empty box.

Alternative tried: I tried setting the icon using setCompoundDrawablesWithIntrinsicBounds, but even after much hair-pulling, it didn't work properly.

So, is there a way to get rid of the message-box in setError?

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
  • Check this out. Same question. http://stackoverflow.com/questions/8985295/edittext-seterror-with-icon-but-without-popup-message – Rohit5k2 Feb 01 '16 at 09:59

2 Answers2

1

As Patel Hiren suggested in the comment, creating a custom class that extends EditText and overriding the setError method there solved my issue:

public class MyEditText extends EditText {

    public MyEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setError(CharSequence error, Drawable icon) {
        setCompoundDrawables(null, null, icon, null);
    }
}

Also, in my layout file, I had to replace EditText with the fully qualified name (which is packagename.className) of this class. It worked fine.

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
0

You can set where you want firstName.setError(null);

Patel Hiren
  • 61
  • 11
  • This'll remove the error symbol also. I just want to remove the error text, not the symbol. – Akeshwar Jha Feb 01 '16 at 11:59
  • You just want to error symbol right. you can try this public class MyEditText extends EditText { public MyEditText(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void setError(CharSequence error, Drawable icon) { setCompoundDrawables(null, null, icon, null); } } – Patel Hiren Feb 02 '16 at 05:00