TrolliOlli TrolliOlli - 2 months ago 19
Android Question

Programmatically make a color more transparent

I'm working on a simple bar graph application that uses a static array of colors for divvying out bar colors. I would like the functionality to either draw bars normally, or slightly transparent.

Is there a way to programmatically adjust a color integer so that it's slightly transparent? Or will I have to statically define a transparent version of each color and then switch to using these versions whenever I want transparency?


Sure...Look at Color and there's a function:

static int   argb(int alpha, int red, int green, int blue)

Return a color-int from alpha, red, green, blue components.

So your RGB values could be static and you just bump the alpha value to get a new transparent version of the color.