EditText setError()删除drawable权限

时间:2013-10-10 09:47:38

标签: android

我有EditText 在其中写的XML:android:drawableRight="@drawable/promotion_create_promotion_plus_icn"

setError("sss") drawableRight更改时。

我希望setError(null) drawableRight返回时为drawable/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" />

在java中:

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

谁能帮助我?

2 个答案:

答案 0 :(得分:5)

问题是setError(null)也会清除图标。 要恢复原始版本,请添加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);
}

答案 1 :(得分:0)

您必须用EditText包装TextInputLayout并为textInputLayout而不是editText设置错误