Created
October 18, 2015 00:24
-
-
Save patrickhammond/c3569ebde0a88f93dd0f to your computer and use it in GitHub Desktop.
Drawable helper
This file contains 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
import android.content.Context; | |
import android.graphics.drawable.Drawable; | |
import android.support.annotation.ColorRes; | |
import android.support.annotation.DrawableRes; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v4.graphics.drawable.DrawableCompat; | |
public class DrawableHelper { | |
public static Drawable setupTintedIcon(Context context, @DrawableRes int iconDrawableResId, @ColorRes int iconColorResId) { | |
Drawable icon = ContextCompat.getDrawable(context, iconDrawableResId); | |
Drawable wrappedIcon = DrawableCompat.wrap(icon); | |
int iconColor = ContextCompat.getColor(context, iconColorResId); | |
DrawableCompat.setTint(wrappedIcon.mutate(), iconColor); | |
return wrappedIcon; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To tint with a ColorStateList: