Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 614
android developer Avatar asked Jan 20 '13 15:01

android developer


People also ask

How do I start an activity background?

Intent dialogIntent = new Intent(this, Adscreen. class); dialogIntent. addFlags(Intent. FLAG_ACTIVITY_NEW_TASK); startActivity(dialogIntent);

What is window background?

The window background is the color or pattern used to fill the client area before a window begins drawing.

What is windowBackground in Android?

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.


1 Answers

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

like image 80
numan salati Avatar answered Oct 09 '22 20:10

numan salati