![](/img/trans.png)
[英]How to remove the tint color of EditText or set it to default style in android?
[英]How to remove tint color from drawable in edittext?
美好的一天。 我有一个问题。 我将EditText drawable的颜色更改为焦点,并在焦点更改时将其更改为默认颜色。 一切都很好,直到支持库更新(这是我的假设)现在,drawable的颜色不会切换回正常。 感谢大家提前=)
这是我的代码:
@Override
public Drawable setTint(Drawable d, int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(d);
DrawableCompat.setTint(wrappedDrawable, color);
return wrappedDrawable;
}
@Override
public void setEditTextDrawables(final EditText editText, final int drawable) {
editText.setCompoundDrawablesWithIntrinsicBounds(drawable, 0, 0, 0);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b){
Drawable icon = getResources().getDrawable(drawable);
editText.setCompoundDrawablesWithIntrinsicBounds(setTint(icon,
getResources().getColor(R.color.colorAccent)), null, null, null);
}else if (!b){
Drawable icon = getResources().getDrawable(drawable);
editText.setCompoundDrawablesWithIntrinsicBounds(setTint(icon,
getResources().getColor(R.color.colorGreyIcon)), null, null, null);
}
}
});
}
这是应用程序的屏幕:
根据Drawable#setTint(int)上的Android文档:
要清除色调,
setTintList(ColorStateList)
null
传递给setTintList(ColorStateList)
。
注意:如果您之前已在活动中的相同Drawable Id上设置了色调,则仅调用getDrawable(int)
来创建新的Drawable不足以清除色调。
请注意, setTintList( null )
仅适用于21以上的API(Android 5.0,Lollipop)。 因此,建议使用ImageViewCompat
:
ImageViewCompat.setImageTintList( iv,null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.