4

Anyone else experiencing issues with the status bar always being grey since using sdk 26 or 27? I recently updated Android Studio and using 27 as my target sdk and now every Activity that is launched has a grey status bar. I have not changed the styles or themes, yet they are always grey.

Another interesting development is my MainActivity has a navigation drawer there and it has no issues rendering a translucent status over my primary colour. But every Activity I launch from there always has the grey status bar. I am completely lost as to why but I am assuming it's the SDK version since I had no issues before.

Every Activity references this style, which used to work for both the MainActivity and all other Activities:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

I can fix the grey problem by removing the translucent flag and setting the status bar colour manually in xml. However this now breaks the MainActivity's navigation drawer opening under the translucent status bar (it's just the solid colour). In a perfect world I would want the translucent status bar over my primary colour in all activities.

Any help would be appreciated!

UPDATE: I can confirm the issue manifests itself if I use SDK 27 and update the support dependencies with it. If I go back to SDK 26 versions, the problem seems to go away. Is there something specifically related to 27 that we need to be aware of?

JPM
  • 1,482
  • 5
  • 18
  • 25
  • I'm having a similar issue with this changed behaviour on API 27 and am just starting to investigate why. So I concur it's a genuine problem – Simon Hutton Mar 15 '18 at 13:13

4 Answers4

5

Add this line in your styles.xml(v21):

<item name="android:statusBarColor">@color/PrimaryDark</item>

It may solve your problem.

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
  • If I add this to my styles.xml, it works, but with the translucent flag set to true, the MainActivity's status bar becomes extremely dark, while the launched activities are still grey. Now if I set the translucent flag to false, the navigation drawer no longer slides under the transparent status bar and it slides under the primary dark colour. Seems like 27 has changed something related to this as the launched activities seem to not handle both the translucent flag and a status bar colour on the launched activities. – JPM Mar 15 '18 at 13:39
  • "Seems like 27 has changed something". That's DEFINITELY true – Simon Hutton Mar 15 '18 at 15:05
3

As I stated in my comment, I was having a similar problem that only started to manifest itself in API27. The status bar isn't specifically grey - it's just transparent.

My particular solution was that the styles.xml in my values-v21 folder was as follows :-

  <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Removing the android:statusBarColor row fixed the issue for me.

The reason I'm posting this as an answer is that in earlier API versions this iffy line had not affected the status bar - which is probably a separate issue in itself. It seems that that issue has been fixed in API27 which is why the status bar is now appearing transparent.

Simon Hutton
  • 1,677
  • 3
  • 22
  • 35
  • This doesn't work for me. The status bar is now white to match the colour of the activity, while the MainActivity is using the primary colour which is now matching the toolbar colour. The navigation drawer is fine though, so I am still not sure why this is happening. – JPM Mar 15 '18 at 13:50
  • To clarify, in your launched activities, how are you setting the status bar colour? – JPM Mar 15 '18 at 13:59
  • I'm just using the Material Design default of `colorPrimaryDark` which I've set in colors.xml. I don't believe you have to specifically override it (which is what Masoud has done in his answer). – Simon Hutton Mar 15 '18 at 14:49
  • https://developer.android.com/guide/topics/ui/look-and-feel/themes.html#CustomizeTheme – Simon Hutton Mar 15 '18 at 14:53
  • Oh okay. For whatever reason any launched activitiy is not picking up the colour like my MainActivity does. I am not programmatically changing the colour in code in any Activity nor have I changed my styles.xml. I thought perhaps there may be something in my layout files that is doing something it shouldn't but creating a brand new Activity in Android Studio produces the white status bar as well when I launch it. – JPM Mar 15 '18 at 15:54
1

Same problem with API 27.

In styles.xml(v21) I have:

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowActivityTransitions">true</item>
    </style> 

Then I added this, in root layout of my application:

       android:background="@color/colorPrimary"
       android:fitsSystemWindows="true"

That solved my problem.

I'm using a second CoordinatorLayout that wrap the AppBar as suggested in this answer for not showing the AppBar's shadow over the Status Bar

As I can see the issue is that the root CoordinatorLayout is drawed behind the StatusBar, with white color as background, but the AppBar is not.

Edit: After some more tests I can says that using in styles.xml(21): @android:color/transparent

        <item name="android:windowTranslucentStatus">true</item> 

and using in my root layout:

   android:background="@color/colorPrimaryDark"

results in a better color feeling.

Ossi
  • 31
  • 7
1

It still doesn't work in SDK 28 but to set the backgrounds is a good fix for this problem e.g.:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/defaultBackground"
        android:orientation="vertical">

        <!-- Some content -->
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>
siergiejjdw
  • 601
  • 5
  • 7