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 FF
means it's not transparent at all. A value of 00
means 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 0x016569C1
which has an Alpha values of 1 (barely visible). Put, 0xFFFF0000
and you'll have a red background.
You are passing in the color incorrectly. DeeV got to it before me but you need to use a hex value.
Here is a link that lists all combinations for easy access.
Colors for Android
You can also set in the XML by using
android:background = "#FF00000000"
Which would be black.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With