Skip to content

Instantly share code, notes, and snippets.

@subinkrishna
Created May 3, 2016 17:35
Show Gist options
  • Save subinkrishna/3fd01dde8208386fe8aa8c91ce1b3aaf to your computer and use it in GitHub Desktop.
Save subinkrishna/3fd01dde8208386fe8aa8c91ce1b3aaf to your computer and use it in GitHub Desktop.
Apply tint & bounds to a drawable
/**
* Applies tint & bound to a drawable.
*
* @param context
* @param drawableRes
* @param colorRes
* @param sizeRes
* @return
*/
public static Drawable applyTintAndBounds(Context context,
@DrawableRes int drawableRes,
@ColorRes int colorRes,
@DimenRes int sizeRes) {
if (null == context)
return null;
Drawable d = ContextCompat.getDrawable(context, drawableRes);
// Tint
int color = ContextCompat.getColor(context, colorRes);
d = DrawableCompat.wrap(d).mutate();
DrawableCompat.setTint(d, color);
// Bounds
int w = context.getResources().getDimensionPixelSize(sizeRes);
d.setBounds(0, 0, w, w);
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment