A
Maybe something like that:DrawableCompat.setTint(imageView.getDrawable(), ContextCompat.getColor(context, R.color.yourColor));
or such:public class TintIcon {
private static int[][] states = new int[][] {
new int[] { android.R.attr.state_pressed},
new int[] { android.R.attr.state_focused},
new int[] { android.R.attr.state_selected},
new int[] { -android.R.attr.state_selected}
};
private static int[] colors = new int[] {
Color.parseColor("#4EA62E"), // primary color
Color.parseColor("#4EA62E"), // primary color
Color.parseColor("#4EA62E"), // primary color
Color.parseColor("#868686") // grey icon
};
private static int[] colorsSwitch = new int[] {
Color.parseColor("#D7B00F"), // yellow color
Color.parseColor("#D7B00F"), // yellow color
Color.parseColor("#D7B00F"), // yellow color
Color.parseColor("#868686") // grey icon////
};
private static ColorStateList myColorStateList = new ColorStateList(states,colors);
private static ColorStateList myColorStateListSwitch = new ColorStateList(states,colorsSwitch);
public static Drawable tintIconToGreenColor(Context context, Drawable icon) {
if (icon != null) {
icon = DrawableCompat.wrap(icon).mutate();
DrawableCompat.setTintList(icon, myColorStateList );
DrawableCompat.setTintMode(icon, PorterDuff.Mode.SRC_IN);
}
return icon;
}
public static Drawable tintIconYellowColor(Context context, Drawable icon) {
if (icon != null) {
icon = DrawableCompat.wrap(icon).mutate();
DrawableCompat.setTintList(icon, myColorStateListSwitch );
DrawableCompat.setTintMode(icon, PorterDuff.Mode.SRC_IN);
}
return icon;
}
}
These two methods tintIconToGreenColor and tintIconYellowColor To paint icon in green and yellow. I'll use it to change the flower of the gravy of the drawing.There's a bacon in it. .png I steal two different colors: