Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText setError() delete the drawable right

Tags:

android

I have EditText in it XML written: android:drawableRight="@drawable/promotion_create_promotion_plus_icn"

when setError("sss") the drawableRight change.

I want when setError(null) the drawableRight return to be drawable/promotion_create_promotion_plus_icn

the XML:

<EditText android:id="@+id/create_benefit_add_titale" style="@style/promotion_create_promotion_add_title_bcg" android:drawableRight="@drawable/promotion_create_promotion_plus_icn" android:hint="@string/create_benefit_add_titale" />

in java:

@Override public void afterTextChanged(Editable s) { ((EditText) getCurrentFocus()).setError(null); }

who can help me?

like image 207
user1882196 Avatar asked Mar 04 '26 12:03

user1882196


1 Answers

The problem is that the setError(null) clears also the icon. To restore the original one, add it programmatically:

@Override public void afterTextChanged(Editable s) {
  EditText edit = (EditText) getCurrentFocus();
  edit.setError(null);
  edit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.promotion_create_promotion_plus_icn, 0);
}
like image 78
Saran Avatar answered Mar 06 '26 00:03

Saran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!