Issue
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:
Solution
According to the Android documentation on Drawable#setTint(int):
To clear the tint, pass
null
tosetTintList(ColorStateList)
.
Note: Just calling getDrawable(int)
to create a new Drawable is not sufficient to clear the tint, if you've previously set the tint on the same Drawable Id in an activity.
Answered By - Funktional
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.