Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove tint color from drawable in edittext?

Good day. I have an issue. I change the color of EditText drawable when it's in focus and change it back to default color when focus changes. And everything was good until support library updated(that's my assumption)now the color of a drawable doesn't switch back to normal. Thank's everyone in advance =)

This is my code:

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

and this is screens from the app:

enter image description here

enter image description here

like image 684
Vlad Zbuker Avatar asked Sep 02 '16 14:09

Vlad Zbuker


1 Answers

Note that setTintList( null ) will only work on API's above 21 (Android 5.0, Lollipop). Therefore the use of ImageViewCompat is recommended:

ImageViewCompat.setImageTintList( iv,null);
like image 141
Peter Avatar answered Oct 09 '22 18:10

Peter