【问题标题】:How to change statusBar background and icons color on Android如何在 Android 上更改 statusBar 背景和图标颜色
【发布时间】:2018-03-21 12:06:51
【问题描述】:

在我的应用程序中,我想将 transparent 背景设置为 statusBar,并将 white 颜色设置为 statusBar icons

我编写下面的代码并将 transparent 背景设置为 statusBarnavigationBar

但我只想将透明背景设置为statusBar不是导航栏)并将statusBar图标颜色从黑色变为白色 .

样式代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.DayNight">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary21</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:colorBackground">@color/white</item>

        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">false</item>
    </style>
</resources>

Java 代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    Window w = getWindow();
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

并将此标志设置为 rootLayout : android:fitsSystemWindows="true"

我的代码结果是:

我该如何解决?请帮我

【问题讨论】:

  • @AkshayKatariya,请查看我的代码,我用您的链接编写代码。但告诉我上面的结果
  • @AkshayKatariya,上面的链接设置为导航栏透明。我只想设置透明状态栏

标签: java android android-styles


【解决方案1】:

你可以用这个:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.ransparent_color_resource));
    }

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2021-03-25
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 2014-01-13
    • 2014-11-08
    相关资源
    最近更新 更多