Android - Change only the alpha TextView's text

alpha, android, colors, textview

Solution

Well, the straight answer to your question of "if color is 0x00ffffff, how would I change it to 0xffffffff ?" to simply to use compound bitwise or: `color |= 0xff000000;`.

But I reckon maybe some co-workers would rather you didn't do this kind of thing on the java-side of Android development: you have a wonderful helper class called `graphics.Color` provided by Android! It does just the same things underneath, but'll really help your code readibility, especially considering that an `int` type color in android isn't necessarily a hex color value but could also point to an artbirary id of a resource in the `color` xml. Argh.

An eg would be:

int color = tv.getCurrentTextColor();
int newColor = Color.argb(yourNewAlphaVal, Color.red(color), Color.green(color), Color.blue(color))

Not fast, but I'm guessing you don't need it to be.

Of course, this is a personal opinion about what to use here, and I hope this helps!

Problem

Say I have this code: ``` int color = tv.getCurrentTextColor(); ``` How would I change only the Alpha on this color? For Example: if color is `0x00ffffff`, how would I change it to `0xffffffff` ? Is there a method for that or I need to do some hex/int manipulations?

Original source