如何从 edittext 中的 drawable 中删除色调颜色?

How to remove tint color from drawable in edittext?

美好的一天。我有一个问题。我在 EditText 处于焦点时更改可绘制的颜色,并在焦点更改时将其更改回默认颜色。在更新支持库之前一切都很好(这是我的假设)现在可绘制对象的颜色不会切换回正常。提前谢谢大家=)

这是我的代码:

@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);
            }
        }
    });
}

这是来自应用程序的屏幕:

According to the Android documentation on Drawable#setTint(int):

To clear the tint, pass null to setTintList(ColorStateList).

注意:如果您之前已经在 activity 中的同一个 Drawable Id 上设置了色调,则仅调用 getDrawable(int) 来创建一个新的 Drawable 不足以清除色调。

请注意,setTintList( null ) 仅适用于 API 的 21 岁以上(Android 5.0,Lollipop)。因此建议使用ImageViewCompat

ImageViewCompat.setImageTintList( iv,null);