简体   繁体   English

状态栏和导航栏的颜色不会改变

[英]Status bar and navbar color won't change

I want to change color of navbar and status bar in Android 5 Lolipop app. 我想在Android 5 Lolipop应用中更改导航栏和状态栏的颜色。

Here are my manifest sdk settings: 这是我的清单SDK设置:

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

I have this in my my_style.xml file : 我的my_style.xml文件中有此文件:

<?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). 如果我更改android:colorPrimary color,则条形图的android:colorPrimary颜色(而不是状态栏/导航条)在IDE中的布局以及调试Android应用程序时也会发生变化,但是statusBarColornavigationBarColor不会执行任何操作( https://developer.android.com/training/ material / theme.html-在这里您可以看到)。 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 ): 我通过添加标志(Scala代码)解决了这个问题:

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 它在应用程序中有效,但布局编辑器仍未在app_style.xml显示android:statusBarColorandroid:navigationBarColor项的app_style.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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