【发布时间】:2018-03-21 12:06:51
【问题描述】:
在我的应用程序中,我想将 transparent 背景设置为 statusBar,并将 white 颜色设置为 statusBar icons。
我编写下面的代码并将 transparent 背景设置为 statusBar 和 navigationBar 。
但我只想将透明背景设置为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