Last active
January 13, 2017 00:11
-
-
Save MinceMan/cf9dd39b5de31c9e8929c8e16eb45b36 to your computer and use it in GitHub Desktop.
TintingColorFilter
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
public final class TintingColorFilter { | |
private TintingColorFilter() { } | |
/** | |
* @param color, The rgb color you would like to tint with. | |
* @param alpha, How strong you would like the color to tint. 0 is none, 1 is completely. | |
*/ | |
public static ColorFilter createFilter(@ColorInt int color, float alpha) { | |
int red = Color.red(color); | |
int green = Color.green(color); | |
int blue = Color.blue(color); | |
int alphaColor = Color.argb((int) ((alpha * 255)), red, green, blue); | |
return new PorterDuffColorFilter(alphaColor, Mode.SRC_ATOP); | |
} | |
} |
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
class TintingColorFilterExample { | |
Drawable drawable; | |
void tint() { | |
ColorFilter filter = TintingColorFilter.createFilter(Color.RED, 1); | |
drawable.setColorFilter(filter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment