Stack Overflow archive
1 scoreaccepted

Calculating Material Colors

score
1
question views
770
license
CC BY-SA 3.0

You can use the following method to get a darker primary color:

java
/**
 * Darkens a color by a given factor.
 *
 * @param color
 *     the color to darken
 * @param factor
 *     The factor to darken the color.
 * @return darker version of specified color.
 */
@ColorInt public static int darker(@ColorInt int color, @FloatRange(from = 0.0, to = 1.0) float factor) {
  return Color.argb(Color.alpha(color), 
      Math.max((int) (Color.red(color) * factor), 0),
      Math.max((int) (Color.green(color) * factor), 0),
      Math.max((int) (Color.blue(color) * factor), 0)
  );
}

Example:

java
int primaryDark = darker(primaryColor, 0.85f);

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.