Status Bar Color not showing - 5.0 Lollipop Android Studio: (AppCompat-v7:r21)

38,270

Solution 1

Please read this: For this to take effect, the window must be drawing the system bar backgrounds with

android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS

but

android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS

must not be set (Source)

In case of you don't know how to add that flag:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

Solution 2

This worked for me:

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.some_color));
    }

Solution 3

Did you set the target SDK version to 21? I had the same issue when I left the target SDK version to 19. You can leave the min SDK to anything lower.

And of course you need to inherit from the proper theme and make sure your Activity uses it.

Solution 4

Check if you are editing styles.xml in values-v21 folder. If you set SDK version to 21 then it won't look for styles.xml in values folder(but it should do so).

enter image description here

Solution 5

test on my nexus7 5.1.1

set in style.xml v21/v22 is not work

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/holo_red_dark</item>

but

set in actvivity

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(getResources().getColor(android.R.color.holo_red_dark));
}

is work for me

Share:
38,270
Adifyr
Author by

Adifyr

I'm a Full Stack Developer that specializes in Mobile UX Design &amp; Development. Like gaming and reading. Currently exploring Blockchain &amp; NFTs.

Updated on July 09, 2022

Comments

  • Adifyr
    Adifyr almost 2 years

    I'm using the AppCompat-v7:21.0.0 support library for Android 5.0 Lollipop in Android Studio. My problem is that the Status Bar Color that can be changed by setting colorPrimaryDark in the values/styles.xml file, is showing up as black, in both the xml layout preview and the emulator.

    So what's wrong? Am I missing something? Please let me know. Thanks.

    EDIT: I'm aware of the fact that changing the status bar color on Pre-Lollipop versions is not possible. My XML Layout Editor Preview and my Emulator are both set to API Level 21 (5.0 Lollipop). But, the status bar still isn't of the color I set it to in colorPrimaryDark. I tried doing statusBarColor in styles.xml but to no avail. It's still black.

    ALSO: I saw one of the answers on a similar question where they advised me to put my minSdkVersion to 21. I tried that, but it didn't work. And I want my app to run on devices with API Level 15 and above.