How to change background color in android app


Question

I want to be able to change the background color to white in my android app in the simplest way possible.

1
238
12/24/2014 5:11:15 AM

Accepted Answer

You need to use the android:background property , eg

android:background="@color/white"

Also you need to add a value for white in the strings.xml

<color name="white">#FFFFFF</color>

Edit : 18th Nov 2012

The first two letters of an 8 letter color code provide the alpha value, if you are using the html 6 letter color notation the color is opaque.

Eg :

enter image description here

340
11/18/2012 12:23:45 PM

You can also use

android:background="#ffffff"

in your xml layout or /res/layout/activity_main.xml, or you can change the theme in your AndroidManifest.xml by adding

android:theme="@android:style/Theme.Light"

to your activity tag.

If you want to change the background dynamically, use

YourView.setBackgroundColor(Color.argb(255, 255, 255, 255));

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon