Skip to content

Instantly share code, notes, and snippets.

@kamilZ
Created January 20, 2014 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilZ/8519003 to your computer and use it in GitHub Desktop.
Save kamilZ/8519003 to your computer and use it in GitHub Desktop.
Darken Android color.
public static int darken(int color, double fraction) {
int red = (int) Math.round(Math.max(Color.red(color) + 255 * fraction,255));
int green = (int) Math.round(Math.max( Color.green(color) + 255 * fraction,255));
int blue = (int) Math.round(Math.max( Color.blue(color) + 255 * fraction,255));
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
@martintreurnicht
Copy link

This doesn't work, here is a link to a working lighten and darken piece of code https://gist.github.com/martintreurnicht/f6bbb20a43211bc2060e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment