private void tintDrawables() { final ColorStateList textColors = getTextColors(); if (textColors != null) { for (Drawable drawable : getAllCompoundDrawables()) { if (drawable instanceof TintedDrawable) { ((TintedDrawable) drawable).setTintListCompat(textColors); } } invalidate(); } }
private Drawable[] getAllCompoundDrawables() { Drawable[] drawables = new Drawable[6]; Drawable[] compoundDrawables = getCompoundDrawables(); drawables[0] = compoundDrawables[0]; // left drawables[1] = compoundDrawables[1]; // top drawables[2] = compoundDrawables[2]; // right drawables[3] = compoundDrawables[3]; // bottom if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative(); drawables[4] = compoundDrawablesRelative[0]; // start drawables[5] = compoundDrawablesRelative[2]; // end } return drawables; }
public NavigationBarButton(Context context, AttributeSet attrs) { super(context, attrs); init(); }
private void init() { // Unfortunately, drawableStart and drawableEnd set through XML does not call the setter, // so manually getting it and wrapping it in the compat drawable. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Drawable[] drawables = getCompoundDrawablesRelative(); for (int i = 0; i < drawables.length; i++) { if (drawables[i] != null) { drawables[i] = TintedDrawable.wrap(drawables[i]); } } setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], drawables[1], drawables[2], drawables[3]); } }
@Override public void setTextColor(ColorStateList colors) { super.setTextColor(colors); tintDrawables(); }
@Override public void setCompoundDrawablesRelative(Drawable start, Drawable top, Drawable end, Drawable bottom) { if (start != null) start = TintedDrawable.wrap(start); if (top != null) top = TintedDrawable.wrap(top); if (end != null) end = TintedDrawable.wrap(end); if (bottom != null) bottom = TintedDrawable.wrap(bottom); super.setCompoundDrawablesRelative(start, top, end, bottom); tintDrawables(); }
@Override public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) { if (left != null) left = TintedDrawable.wrap(left); if (top != null) top = TintedDrawable.wrap(top); if (right != null) right = TintedDrawable.wrap(right); if (bottom != null) bottom = TintedDrawable.wrap(bottom); super.setCompoundDrawables(left, top, right, bottom); tintDrawables(); }
public NavigationBarButton(Context context) { super(context); init(); }