I'm trying to set the background color of a View (in this case a Button).
I use this code:
// set the background to green
v.setBackgroundColor(0x0000FF00 );
v.invalidate();
It causes the Button to disappear from the screen. What am I doing wrong, and what is the correct way to change the background color on any View?
Thanks.
Several choices to do this...
Set background to green:
Set background to green with Alpha:
Set background to green with Color.GREEN constant:
Set background to green defining in Colors.xml
and using:
and:
or the longer winded:
and:
For setting the first color to be seen on screen, you can also do it in the relevant layout.xml (better design) by adding this property to the relevant View:
You can simple use :
You can simple use :
Stating with Android 6 use ContextCompact