简体   繁体   中英

Status bar and navbar color won't change

I want to change color of navbar and status bar in Android 5 Lolipop app.

Here are my manifest sdk settings:

<uses-sdk android:minSdkVersion="21"
          android:targetSdkVersion="21"
          android:maxSdkVersion="21" />

I have this in my my_style.xml file :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- inherit from the material theme -->
    <style name="AppTheme" parent="android:Theme.Material">
        <!-- Main theme colors -->
        <!--   your app branding color for the app bar -->
        <item name="android:colorPrimary">@color/primary</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="android:colorAccent">@color/accent</item>

        <item name="android:statusBarColor">@color/navbar</item>
        <item name="android:navigationBarColor">@color/navbar</item>
    </style>
</resources>

If I change android:colorPrimary color of bar (not status bar/navbar) also changes on layout in IDE and when debugging Android app, but statusBarColor and navigationBarColor doesn't do anything ( https://developer.android.com/training/material/theme.html - here you can see that it should). I even tried to do:

getWindow.setStatusBarColor(Integer.parseInt("00FF00", 16))

but it also doesn't work. Am I missing something ?

I solved that by adding flag ( Scala code ):

getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)

before

setContentView(R.layout.main)

it works in app, but still layout editor doesn't show changes of android:statusBarColor and android:navigationBarColor items in app_style.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM