透明状态栏不适用于 windowTranslucentNavigation="false" [英] Transparent status bar not working with windowTranslucentNavigation="false"

查看:49
本文介绍了透明状态栏不适用于 windowTranslucentNavigation="false"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Activity,我需要在运行 5.0+ (API 21+) 的设备上使导航栏不透明,状态栏透明.我使用的样式如下,以及我的问题的解释.

I am developing an Activity where I need to make the navigation bar opaque, and the status bar transparent on devices running 5.0+ (API 21+). The styles I am using are below, along with an explanation of my problem.

AppTheme 扩展 Theme.AppCompat.Light.NoActionBar

<item name="android:statusBarColor">@color/transparent</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/welbe_red_transparent</item>

FullscreenTheme 扩展 AppTheme

<item name="android:windowNoTitle">true</item>
<item name="android:statusBarColor">@color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>

这使应用程序看起来像这样

This makes the app look like this

如果我删除 android:windowTranslucentNavigation 样式,或在 Fullscreen 中将其设置为 false,它会修复导航栏问题.问题是状态栏变成了完全白色,而不是保持透明并显示其后面的内容.

If I remove the android:windowTranslucentNavigation style, or set it to false in Fullscreen, it fixes the navigation bar issue. The problem is the status bar turns completely white instead of staying transparent and displaying the content behind it.

我曾尝试在我的布局中使用 fitsSystemWindow="true",但它没有解决问题.有人知道为什么会这样吗?

I have tried using fitsSystemWindow="true" in my layouts, but it didn't fix the issue. Anyone know why this is happening?

推荐答案

android:windowTranslucentNavigation 做了一件 android:statusBarColor 没有做的事情,那就是请求SYSTEM_UI_FLAG_LAYOUT_STABLESYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 标志.

android:windowTranslucentNavigation does one thing that android:statusBarColor doesn't do, which is requesting the SYSTEM_UI_FLAG_LAYOUT_STABLE and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN flags.

这些是您需要请求才能在状态栏后面绘制的内容.

These are the ones that you need to request in order to draw behind the status bar.

在您的 ActivityonCreate 中请求它们:

Request them in the onCreate of your Activity:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

或者,您也可以简单地设置您的应用主题背景,它也会在您的状态栏后面弹出.

Alternatively you can also simply set your apps theme background and that will also pop up behind your status bar.

更多信息此处.

这篇关于透明状态栏不适用于 windowTranslucentNavigation="false"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆