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

前端 未结 11 1332
-上瘾入骨i
-上瘾入骨i 2020-12-23 20:02

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 se

相关标签:
11条回答
  • 2020-12-23 20:21

    Changing the Status Bar color in pre-Lollipop(5.0) is not possible by setting colorPrimaryDark. See this article.

    On older platforms, AppCompat emulates the color theming where possible. At the moment this is limited to coloring the action bar and some widgets.

    0 讨论(0)
  • 2020-12-23 20:23

    I was working on an old app and trying to convert it to material style. The code and everything was fine however the only mistake I had that was hindering the status bar tinting on >= Lollipop devices was "TargetSDKVersion" in build.gradle. It was set to less then 21. I changed it to 21 and statusbar tinting started working.

    0 讨论(0)
  • 2020-12-23 20:24

    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);
    
    0 讨论(0)
  • 2020-12-23 20:24

    In v22-appcompat they (Android) have now added rendering of the status bar color in the android studio preview!

    About time... Anyways, make sure your appcompat library is updated to the latest version, which is v22.0.+.

    Cheers!

    0 讨论(0)
  • 2020-12-23 20:25

    This worked for me. Removed the status bar color from styles. Add flag and then put the color you want like so

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.your_color));
    }
    
    0 讨论(0)
  • 2020-12-23 20:28

    In my case, the culprit was jfeinstein10/SlidingMenu library. I replaced the library with Android navigation drawer and now it displays status bar color correctly.

    0 讨论(0)
提交回复
热议问题