Skip to content

Instantly share code, notes, and snippets.

@vsay01
Created May 13, 2018 13:57
Show Gist options
  • Save vsay01/ab72627cd18d15534d879712580b2562 to your computer and use it in GitHub Desktop.
Save vsay01/ab72627cd18d15534d879712580b2562 to your computer and use it in GitHub Desktop.
/**
* https://stackoverflow.com/questions/33072365/how-to-darken-a-given-color-int
* @param color color provided
* @param factor factor to make color darker
* @return int as darker color
*/
public static int manipulateColor(int color, float factor) {
int a = Color.alpha(color);
int r = Math.round(Color.red(color) * factor);
int g = Math.round(Color.green(color) * factor);
int b = Math.round(Color.blue(color) * factor);
return Color.argb(a,
Math.min(r, 255),
Math.min(g, 255),
Math.min(b, 255));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment