Maybe something like this:
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 color the icon in green and yellow. I use it to change the color of the picture on the gray icon.
I paint this icon in .png in two different colors:
