Color Manipulation

suggest change

Change a color by reading its alpha, red, green, and blue channels, then writing them back.

Extract the RGB channels. Color.parseColor accepts a #RRGGBB or #AARRGGBB string. There is no Color.parse.

int yourColor = Color.parseColor("#ae1f67");

int red = Color.red(yourColor);
int green = Color.green(yourColor);
int blue = Color.blue(yourColor);

Adjust the channels, then pack them into a color. Each channel must be in the range 0–255. Color.rgb and Color.argb throw IllegalArgumentException outside that range.

int newColor = Color.rgb(red, green, blue);

To set opacity as well, pass an alpha from 0 (transparent) through 255 (opaque):

int newColor = Color.argb(alpha, red, green, blue);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents