Skip to content

Instantly share code, notes, and snippets.

@Mariuxtheone
Last active August 29, 2015 14:11
Show Gist options
  • Save Mariuxtheone/c0293cd50a291bec9257 to your computer and use it in GitHub Desktop.
Save Mariuxtheone/c0293cd50a291bec9257 to your computer and use it in GitHub Desktop.
Android - Custom ColorFilter to apply new solid color to a Drawable.
ColorFilter getColorFilterFromColor(int color){
//Extract the RGB components from color
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
//create a ColorMatrix with the RGB Components
float[] matrix = {
0, 0, 0, 0, red
, 0, 0, 0, 0, green
, 0, 0, 0, 0, blue
, 0, 0, 0, 1, 0 };
//Return a ColorFilter created with the ColorMatrix
ColorFilter colorFilter = new ColorMatrixColorFilter(matrix);
return colorFilter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment