Difference between android:windowBackground and android:colorBackground?

AndroidAndroid LayoutAndroid Styles

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

> 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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJabKnowsNothingView Question on Stackoverflow
Solution 1 - AndroidabedfarView Answer on Stackoverflow
Solution 2 - AndroidSina AmirshekariView Answer on Stackoverflow