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

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

From: http://stackoverflow.com/questions/14425868/whats-the-difference-between-windowbackground-and-background-for-activities-sty

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

share improve this question
 
up vote 13 down vote accepted

android:background is the background color (drawable to be precise) of a view component where as android:windowBackground is the background color of the window (activity or dialog) in which your view resides.

By default view's 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

share improve this answer
 
 
So why does the activity/application have the android:background, if it actually sets it for each of its views? i don't understand its purpose .btw you can also set an image as a background and not just a color. Also, fixed the confusion of the article. –  android developer Apr 26 '13 at 20:50
 
you can pass any valid android:whatever attribute to any component. it will just ignore the attribute if it doesn't apply for that component. (this can be confusing but its how android ensures backward compatibility). also yes you can pass images, color or any drawable for that matter (gradient, shape even animation) as a value for background and windowBackground. –  numan salati Apr 26 '13 at 22:42
 
but i still don't get how come using an image on android:background on an activity/application makes everything use it, instead of just the background of the activity, and why it even exists there if it has such a weird behavior. you can try this test too : create a new hello world app, and set the theme that was created for you to use this attribute with an image. you will notice that many views on the activity will now use this background. –  android developer Apr 26 '13 at 23:21
 
when you apply styles as a theme on the activity it also applies to the all the view within that activity. again some properties might make sense only at the window level and vice versa - all the properties that don't apply to a component will be ignored. this can be confusing and lead to errors but it also is very flexible. –  numan salati Apr 27 '13 at 14:47
 
interesting. you mean that it's just an example of using styles across the entire app, for example, this way i can set a style of all textView instances if i want to? is this the purpose of the attribute? –  android developer Apr 27 '13 at 14:58

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值