分屏模式下透明导航栏不透明 [英] Transparent navigation bar is not transparent in split screen mode

查看:49
本文介绍了分屏模式下透明导航栏不透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的一个应用程序在支持它的 Android 版本上使用透明的系统栏.这是通过样式中的以下定义来实现的:

An app I am working on uses transparent system bars on Android versions which support it. This is accomplished by the following definition in the style:

<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:statusBarColor">@android:color/transparent</item>

<item name="android:windowDrawsSystemBarBackgrounds">true</item>

以及以下代码:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    /* Make system bars fully transparent */
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}

在正常模式下,这按预期工作:状态和导航栏都覆盖在应用内容上.

In normal mode this works as expected: both the status and the navigation bar are overlaid over the app content.

在分屏模式下,这适用于状态栏,但不适用于导航栏:在纵向模式下,当应用程序位于底部时,导航栏为黑色,但 getWindow().getDecorView().getRootWindowInsets().getSystemWindowInsetBottom() 报告 144 像素的插入.装饰视图的高度比根视图的高度小 144 像素(没有分屏,它们都是相等的,因为应用程序没有操作栏).当应用位于右侧(如导航栏)时,横向模式下的类似症状.

In split-screen mode this works for the status bar but not for the navigation bar: in portrait mode, when the app is at the bottom, the navigation bar is black but getWindow().getDecorView().getRootWindowInsets().getSystemWindowInsetBottom() reports an inset of 144 pixels. The height of the decor view is 144 pixels less than that of the root view (without split screen they are both equal, as the app does not have an action bar). Similar symptoms in landscape mode when the app is on the right (as the navigation bar).

添加 View.SYSTEM_UI_FLAG_LAYOUT_STABLE 标志没有任何效果.

Adding the View.SYSTEM_UI_FLAG_LAYOUT_STABLE flag does not have any effect.

设备是智能手机,即默认为纵向并在横向模式下在侧面显示导航栏的设备.

The device is a smartphone, i.e. a device that defaults to portrait and shows the navigation bar on the side when in landscape mode.

这是我使用的 Android 发行版(LineageOS 15.1、Android 8.1.0)中的一个错误,还是我遗漏了什么?分屏模式下导航栏应该透明吗?如果没有,我如何可靠地确定我的视图的哪些部分将被系统栏遮挡?

Is that a bug in the Android distribution I am using (LineageOS 15.1, Android 8.1.0), or am I missing something? Should the navigation bar be transparent in split screen mode? If not, how can I reliably determine which parts of my view are going to be obscured by the system bars?

推荐答案

由于我仍然无法解释报告的值,我认为这是许多(如果不是全部)Android 版本中存在的错误.

As I still have no explanation for the values reported, I assume this to be a bug present in many (if not all) versions of Android.

此外,显然获取窗口插入的首选方法是覆盖 onApplyWindowsInsets() 并评估传递的 insets 参数(自 API 20 以来就已支持,而以上方式需要API 23).不幸的是,这似乎有自己的一些错误,即报告不正确的顶部插图,但合并这两个结果已经奏效我.

Also, the preferred way to get window insets apparently is to override onApplyWindowsInsets() and evaluate the insets argument passed (which has been supported since API 20, whereas the above way requires API 23). Unfortunately, this seems to have some bugs of its own, namely reporting incorrect top insets, but merging the two results has worked for me.

  • 存储传递给 onApplyWindowsInsets() 的 insets,只丢弃最上面的.
  • 使用存储的值,并依靠 View#getRootWindowInsets() 获取顶部插入.
  • Store the insets passed to onApplyWindowsInsets(), discarding only the top one.
  • Use the stored values, and rely on View#getRootWindowInsets() to get the top inset.

综合价值观对我有用.

这篇关于分屏模式下透明导航栏不透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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