Skip to content

Instantly share code, notes, and snippets.

@MinceMan
Last active January 13, 2017 00:11
Show Gist options
  • Save MinceMan/cf9dd39b5de31c9e8929c8e16eb45b36 to your computer and use it in GitHub Desktop.
Save MinceMan/cf9dd39b5de31c9e8929c8e16eb45b36 to your computer and use it in GitHub Desktop.
TintingColorFilter
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);
}
}
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