EditText setError () remove transfer rights

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

when setError("sss")changes drawableRight.

I want to be setError(null) drawableRightback indrawable/promotion_create_promotion_plus_icn

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?

+4
source share
2 answers

The problem is that it setError(null)also clears the icon. To restore the original, add 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);
}
+5
source

You should wrap EditText TextInputLayoutand set the error for textInputLayoutinsteadeditText

0
source

All Articles