透明的状态栏不工作windowTranslucentNavigation ="假" [英] Transparent status bar not working with windowTranslucentNavigation="false"
问题描述
我开发一个活动
,我需要做的导航栏不透明,运行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.
更多信息<一个href="https://stackoverflow.com/questions/27856603/lollipop-draw-behind-statusbar-with-its-color-set-to-transparent/27923895#27923895">here.
这篇关于透明的状态栏不工作windowTranslucentNavigation =&QUOT;假&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!