android:windowBackground 和 android:colorBackground 的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26266221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between android:windowBackground and android:colorBackground?
提问by JabKnowsNothing
What is the difference between android:windowBackground
and android:colorBackground
?
android:windowBackground
和 和有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?
哪个会影响加载新活动时看到的颜色?
回答by abedfar
windowBackground
only affects the main window's background.
windowBackground
只影响主窗口的背景。
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.
colorBackground
不仅会影响主窗口的背景,还会影响所有组件(例如对话框)的背景,除非您在组件布局中覆盖它。
So both of them change the activity's background, but the colorBackground
changes many more things as well.
所以他们都改变了活动的背景,但也colorBackground
改变了更多的东西。
回答by Sina Amirshekari
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
windowBackground 是样式属性,仅当样式作为主题应用于 Activity 或应用程序时才有效,并且 android:windowBackground 属性仅支持对其他资源的引用;与 android:colorBackground 不同,它不能被赋予颜色文字
http://developer.android.com/guide/topics/ui/themes.html
http://developer.android.com/guide/topics/ui/themes.html
EDITED: i.e. the value of windowBackground must be a referenced color:
编辑:即 windowBackground 的值必须是引用的颜色:
<item name="android:windowBackground">@color/red</item>
but for backgroundColor you can use literals:
但是对于 backgroundColor 你可以使用文字:
<item name="android:colorBackground">#ff0000</item>