14

I have defined a base style for my application with the following element:

<item name="android:windowBackground">@color/window_background</item>

Which has set the background color for all my activities fine until I tested my app on Android 6 where all backgrounds are white. The backgrounds are still color/window_background on devices running pre-marshmallow.

Anyone know how to make this work (or why it is not working) on Android 6?

Edit with some more info: I am targeting API 22, I have not changed anything from previous version or upgraded the API, just running on Android 6 changes the background.

Heinrisch
  • 5,835
  • 4
  • 33
  • 43
  • You are targeting API 22 or API 23 ? – Kamen Stoykov Oct 10 '15 at 09:54
  • I have a similar problem, some of the backgrounds for me were filled with primary color, I've removed `actionBarTheme` from my styles and it seems to fix the background problems. However (how unexpectedly) my action bars are not correctly styled. – Matous Hybl Oct 10 '15 at 17:24
  • Provide more detail in your question like which theme you are using, target API – Dhaval Parmar Oct 14 '15 at 05:40
  • As-is this question is unanswerable. I cannot reproduce the issue with simple blank application and you haven't provided proper MCVE. There is something in your application setup, layouts, views, code that is causing this issue. Without being able to reproduce problem, we can all just wild guess. Even people having similar issues can give you wrong answers because their problem might not be the same as yours. – Dalija Prasnikar Oct 15 '15 at 20:30
  • @DalijaPrasnikar well, I don't really agree. Yes, it might be a guess that someone else is having the same problem, however, that guess might be the thing helping someone. Since I was not the only one with this problem my hope was that someone had solved it and knew what it was. – Heinrisch Oct 16 '15 at 07:35
  • First, you gave extremely little information about your app. Since there is change in behavior between OS versions, there was a good chance that someone would know exact answer and have proper explanation. But it is obvious by now that this is not going to happen. Now would be the right time for you to give more information and MCVE so people that don't have this issue can reproduce it and possibly find the cause. – Dalija Prasnikar Oct 16 '15 at 08:13
  • When you ask question here potential answerers are not only people that know exactly what you are talking about, but other knowledgeable people that can find answer for you if you provide sufficient input. Question itself is certainly interesting enough that someone might start digging to see why and what is happening, once issue can be reproduced in small test app. – Dalija Prasnikar Oct 16 '15 at 08:18
  • @DalijaPrasnikar I would give more info if I could. I have played around with the style files and I have not been able to pin point the issue. I can't post the whole code since its not mine. I don't think there will be much more input in this question and as I have said in other comments, I will give the bounty to the best reply, or is there anything else you think I should do? – Heinrisch Oct 16 '15 at 10:37

4 Answers4

3

I haven't found anything specific for Marshmallow that would cause this. So the suggestions I have are:

Changing the background color resource to a drawable shape resource.

From:

<item name="android:windowBackground">@color/window_background</item>

To:

<item name="android:windowBackground">@drawable/window_background</item>

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/window_background"/>
</shape>

In case you haven't checked the opacity of all your views:

Make sure your windowBackground actually is the background of most of your Activity (particularly over scrollable sections where overdraw is the most important to avoid), removing opaque view backgrounds where possible.

Make your windowBackground work for you instead of using null

I thought this was interesting, to see the precedence of how background layers are set. I am not sure if you are setting any view backgrounds or how you have set up your app, but this is worth a read.

Backgrounds consist of several layers, from back to front:

  • the background Drawable of the theme
  • a solid color (set via setColor(int))
  • two Drawables, previous and current (set via setBitmap(Bitmap) or setDrawable(Drawable)), which may be in transition

BackgroundManager

I can't find if there is a difference with the themes in Marshmallow, or the order of elements, it seems there has been no fundamental changes and I can find no bug for this.

I hope this helps, let me know and I can have another look.

If this doesn't help it may be worth posting some more code relevant to the problem. Cheers.

  • I am experiencing the same problem, but the solution with using shape resource didn't work for me. The biggest problem with this bug(or whatever it is) is that it also happens in for example PreferenceFragment, which is not as easy to override as normal layout. – Matous Hybl Oct 10 '15 at 16:28
  • 1
    Sorry for the delay and thanks for the answer/investigation. I have been playing around with different styles and it seems like their might be something overriding the background. However, I have not really been able to reproduce the problem. Since many people where having the same problem I though there would be an easy answer to this, but I guess there isn't. So triple check your styles people :) I'll give you the bounty if no pin-point answer comes up. Thanks! – Heinrisch Oct 15 '15 at 20:22
1

I used to have a same problem, but I found out by trying that if I commented actionBarTheme in my styles, it started to work suddenly. I dug deeper in my styles and found out that the style of action bar was setting a android:background attribute after commenting it out everything works now as expected.

Matous Hybl
  • 168
  • 1
  • 9
0

If you're using Android Studio 1.4 or higher go to styles where your theme is located and click "Open Editor" in the upper right hand corner. Then change your window background there. It should be under "android:colorBackground"

Chris W
  • 785
  • 8
  • 18
0

How about setting both windowBackground and colorBackground

<item name="android:windowBackground">@color/window_background</item>
<item name="android:colorBackground">@color/window_background</item>
Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159