Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between android:windowBackground and android:colorBackground?

What is the difference between android:windowBackground and android:colorBackground?

Example:

<style name = "theme">  <item name ="android:windowBackground">@color/black</item>  <item name ="android:colorBackground">@color/black</item> </style> 

Which one would affect the color you see when a new activity is loading?

like image 676
JabKnowsNothing Avatar asked Oct 08 '14 20:10

JabKnowsNothing


People also ask

What is window background?

android:background is the background color (drawable to be precise) of a view component whereas android:windowBackground is the background color of the window (activity or dialog) in which your view resides.

How do I change the default background color in android Studio?

Create background color. By default each activity in Android has a white background. To change the background color, first add a new color definition to the colors. xml file in the values resource folder like the following.


2 Answers

windowBackground only affects the main window's background.

colorBackground affects not only the background of the main window but also of all components e.g. dialogs unless you override it in the component layout.

So both of them change the activity's background, but the colorBackground changes many more things as well.

like image 59
abedfar Avatar answered Oct 06 '22 12:10

abedfar


windowBackground are style properties that are effective only when the style is applied as a theme to an Activity or application and android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal

http://developer.android.com/guide/topics/ui/themes.html

EDITED: i.e. the value of windowBackground must be a referenced color:

<item name="android:windowBackground">@color/red</item> 

but for backgroundColor you can use literals:

<item name="android:colorBackground">#ff0000</item> 
like image 37
Sina Amirshekari Avatar answered Oct 06 '22 10:10

Sina Amirshekari