Is it possible to tint the drawableLeft in an android button? I have a black drawable I\'d like to tint white. I know how to achieve this with an image view (image on the le
As @Boris suggested, you can use the support library.
I have extended the AppCompatButton with some draft code. The TintAppCompatButton should have default behaviour but TintAppCompatButtonCustom was made to demo custom coloring.
I’ll see if I can raise a PR to get that into the official support library.
The code of interest is:
private void init() {
PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN;
Drawable[] ds = getCompoundDrawables();
tint(ds[LEFT], Color.RED, tintMode);
tint(ds[TOP], Color.YELLOW, tintMode);
tint(ds[RIGHT], Color.GREEN, tintMode);
tint(ds[BOTTOM], Color.BLUE, tintMode);
}
private void tint(Drawable d, int color, PorterDuff.Mode tintMode) {
TintInfo ti = new TintInfo();
ti.mTintMode = tintMode;
ti.mTintList = ColorStateList.valueOf(color);
ti.mHasTintList = true;
ti.mHasTintMode = true;
TintManager.tintDrawable(d, ti, new int[]{0});
}