I’m trying to figure out one simple thing: how to set a background color in Android view. Here is the code in an Activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View v = new View(this);
setContentView(v);
v.setBackgroundColor(23423425);
}
and all I get is black screen.
The integer you set is easier represented as a hex value. The hex values are
0xAARRGGBB.A – represents the Alpha value which is how transparent the color is. A value of
FFmeans it’s not transparent at all. A value of00means the color won’t be shown at all and everything behind it will be visible.R – Red value; self-explanatory
G – Green value; self-explanatory
B – Blue value; self-explanatory
What you entered in hex is
0x016569C1which has an Alpha values of 1 (barely visible). Put,0xFFFF0000and you’ll have a red background.