Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 587
Adifyr Avatar asked Oct 23 '14 07:10

Adifyr


5 Answers

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);
like image 177
Wayne Avatar answered Nov 16 '22 22:11

Wayne


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));
    }
like image 39
Philipp E. Avatar answered Nov 16 '22 23:11

Philipp E.


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.

like image 12
BladeCoder Avatar answered Nov 16 '22 21:11

BladeCoder


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

like image 7
gkiko Avatar answered Nov 16 '22 21:11

gkiko


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

like image 6
Tryagain Tsai Avatar answered Nov 16 '22 22:11

Tryagain Tsai