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

标签 android android-layout android-5.0-lollipop android-styles

我想在 Android 5 Lolipop 应用程序中更改导航栏和状态栏的颜色。

这是我的 list sdk 设置:

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

我的 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>

如果我更改 android:colorPrimary 栏(不是状态栏/导航栏)的颜色也会在 IDE 中和调试 Android 应用程序时更改布局,但是 statusBarColornavigationBarColor 不执行任何操作(https://developer.android.com/training/material/theme.html - 您可以在此处看到它应该执行的操作)。我什至尝试这样做:

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

但它也不起作用。我错过了什么吗?

最佳答案

我通过添加标志(Scala 代码)解决了这个问题:

getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)

之前

setContentView(R.layout.main)

它在应用程序中工作,但布局编辑器仍然不显示 app_style.xmlandroid:statusBarColorandroid:navigationBarColor 项的更改>

关于android - 状态栏和导航栏颜色不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27077454/

相关文章:

android - 用于动态功能模块的合并测试 apk

android - 出于测试目的,是否有可能在 Google Play 上发布一个我一个人可以访问的应用程序

android - 如何实现像 Google Play 那样的可折叠 View ?

android - 垂直拉伸(stretch) ImageView constraintlayout

Android 省电模式监听器

android - Lollipop 中的多网络

android - GenyMotion 上的 INSTALL_FAILED_NO_MATCHING_ABIS

android - 如何在 Android SQLite 中使用 TRIGGER

android - 使用复选框显示导航(内容)在 Android 上不起作用

android - 找出屏幕上当前显示的是哪个布局文件