透明状态栏无法使用windowTranslucentNavigation ="false"

Aus*_*ney 38 android android-appcompat android-layout android-styles

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

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>
Run Code Online (Sandbox Code Playgroud)

FullscreenTheme 扩展 AppTheme

<item name="android:windowNoTitle">true</item>
<item name="android:statusBarColor">@color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
Run Code Online (Sandbox Code Playgroud)

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

机器人:windowTranslucentNavigation =

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

机器人:windowTranslucentNavigation =

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

Jer*_*ols 68

android:windowTranslucentNavigation做一件事android:statusBarColor没做,就是请求SYSTEM_UI_FLAG_LAYOUT_STABLESYSTEM_UI_FLAG_LAYOUT_FULLSCREEN旗帜.

这些是您需要请求以便在状态栏后面绘制的.

请求onCreate您的Activity:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)

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

更多信息在这里.

  • 正是我需要的!谢谢.文档说"根据需要调整窗口标志",但没有提到哪些标志...... (2认同)
  • 经过大量的搜索和数小时的努力,我终于在这里找到了答案。非常感谢。作为附加说明,我们应该删除“fitsSystemWindows”以使其正常工作。 (2认同)

Sim*_*mas 5

据我所知,没有正确的方法来设置API低于19的状态栏的颜色.

对于API 19+,您windowTranslucentNavigation只能为状态栏使用类似的属性:

<item name="android:windowTranslucentStatus">true</item>
Run Code Online (Sandbox Code Playgroud)

笔记: