Check out the Color class.
Your code will look something like this.
int color = 0xFFFFFFFF; int transparent = Color.argb(0, Color.red(color), Color.green(color), Color.blue(color));
So the wrapper of this method might look like this:
public int adjustAlpha(int color, float factor) { int alpha = Math.round(Color.alpha(color) * factor); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); }
And then name it to set the transparency to, say, 50%:
int halfTransparentColor = adjustAlpha(0xFFFFFFFF, 0.5f);
I think that using the provided Color class is a little more self-documenting, just doing the bit manipulation yourself, plus this is already done for you.
majormajors Mar 10 '13 at 6:43 2013-03-10 06:43
source share