Last active
August 29, 2015 14:11
-
-
Save Mariuxtheone/c0293cd50a291bec9257 to your computer and use it in GitHub Desktop.
Android - Custom ColorFilter to apply new solid color to a Drawable.
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
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