Created
May 3, 2016 17:35
-
-
Save subinkrishna/3fd01dde8208386fe8aa8c91ce1b3aaf to your computer and use it in GitHub Desktop.
Apply tint & bounds to a drawable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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