Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

android - What's the difference between windowBackground and background for activities style?

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 .

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

Example: gist.github.com/floatingmonkey/5474959


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...