透明的状态栏不工作windowTranslucentNavigation ="假"状态栏、透明、工作、QUOT

由网友(◇﹏妄想者βмeι痕迹)分享简介:我开发一个活动,我需要做的导航栏不透明,运行5.0以上(API 21+)设备状态栏透明。是我使用的样式下面,连同我的问题的说明。I am developing an Activity where I need to make the navigation bar opaque, and the status bar...

我开发一个活动,我需要做的导航栏不透明,运行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

AppTheme extends 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

FullscreenTheme extends 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

如果我删除安卓windowTranslucentNavigation 的风格,或将其设置为全屏,它修复了导航栏的问题。现在的问题是状态栏完全变为白色,而不是保持透明,并显示其背后的内容。

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 =真正的在我的布局,但它并没有解决问题。任何人都知道为什么会这样?

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

推荐答案

安卓windowTranslucentNavigation 做一件事是什么安卓statusBarColor 不做,这是要求 SYSTEM_UI_FLAG_LAYOUT_STABLE SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 标志。

android:windowTranslucentNavigation does one thing what 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.

要求他们在的onCreate 活动的:

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.

更多信息here.

阅读全文

相关推荐

最新文章