Difference between android:windowBackground and android:colorBackground?

元气小坏坏 提交于 2019-11-27 10:29:31

问题


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?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/26266221/difference-between-androidwindowbackground-and-androidcolorbackground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!