How to set background color of a View

Peter vdL picture Peter vdL · Feb 1, 2010 · Viewed 445.7k times · Source

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.

Answer

rainhut picture rainhut · Sep 2, 2011

You made your button transparent. The first byte is the alpha.

Try v.setBackgroundColor(0xFF00FF00);