活动风格的 windowBackground 和 background 有什么区别? [英] What's the difference between windowBackground and background for activities style?

查看:19
本文介绍了活动风格的 windowBackground 和 background 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过在样式中使用android:background"参数并将应用程序的主题设置为链接到此样式,我为应用程序的所有活动设置了背景.

I have a background set for all of the activities of the app by using the "android:background" parameter in the styles and setting the theme of the application to link to this style.

一切都很好,直到我注意到对于带有项目列表的对话框,它使每个项目都具有背景的完整大小.

All worked well, till I've noticed that for a dialog with a list of items, it makes each item to have the full size of the background .

将使用的参数更改为android:windowBackground"后,在这种情况下似乎也可以正常工作.

After changing the parameter being used to "android:windowBackground" it seems to work fine in this case too.

为什么会发生?两者有什么区别?

Why does it occur? What is the difference between the two?

另外,是否将android:windowBackground"设置为@null 写在这里提供与使用android:background"相同的速度提升?

Also , does setting "android:windowBackground" to @null as written here provide the same speed boost as using "android:background"?

推荐答案

android:background 是视图组件的背景颜色(准确地说是可绘制的),而 android:windowBackgroundcode> 是视图所在的窗口(活动或对话框)的背景颜色.

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.

默认情况下,视图是透明的(即没有背景颜色),因此在视觉上看起来它们是从底层窗口获取颜色的.

By default views are transparent (i.e. no background color) so visually it looks like they are taking the color from the underlying window.

注意您链接到的文章如何提到将 windowBackground 设置为 null 而不是全屏视图的背景.这是避免过度绘制的常用技术.

Notice how the article you linked to mentions setting the windowBackground to null and not the background for fullscreen views. This is a common technique to avoid overdraws.

但是如果您有一个视图完全隐藏另一个视图,则可以将相同的原则应用于视图.

But the same principle can be applied to views if you have one view completely hide the other view.

示例:gist.github.com/floatingmonkey/5474959

这篇关于活动风格的 windowBackground 和 background 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆