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:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With