Android:全屏系统可见性破坏了窗口插图 [英] Android : Fullscreen system visibility screws up window insets

查看:87
本文介绍了Android:全屏系统可见性破坏了窗口插图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个具有一个活动和一堆片段的应用程序,其中一个片段是全屏显示.为了实现这一点,我正在尝试使用系统UI可见性"标志.

I'm writing an app that has one activity and a bunch of fragments and one of those fragments is fullscreen. In order to achieve that, I'm trying to use the System UI Visibility flags.

对于全屏片段,我设置可见性:

For the fullscreen fragment, I set the visibility:

layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

我这样做后,窗口插图立即更改为似乎没有任何意义的值.然后,当我退出该全屏片段时,我的视图上出现了错误的填充(基于奇怪的插图)

As soon as I do that, the window insets change to values that don't seem to make any sense. Then, when I exit that fullscreen fragment, I wind up with wrong padding on my view (based on the weird insets)

有人知道这是怎么回事吗?我理解窗口插图的方式一定是错误的,因为这种行为似乎完全违背了直觉.任何见识将不胜感激.

Does anyone know what's going on here? The way I understand the window insets must be wrong, because this behavior seems completely counter intuitive. Any insight would be appreciated.

要查看我为说明问题而编写的测试应用程序的完整源代码,请访问此处:

To view the full source of the test app I wrote to illustrate the problem go here:

https://github.com/dapp/visibilitytest

推荐答案

我今天遇到了同样的问题.我正在使用设计库中的NavigationView.当我退出全屏显示时,NavigationView的顶部和底部都有昆虫,这很丑.

I have the same problem today. I am using a NavigationView from design library. When I exit full screen, there are insects on top and bottom of NavigationView, which is ugly.

我调试并挖掘了NavigationView的源代码,并找到以下解决方案:

I debug and dig into the source code of NavigationView and find following solution:

  1. 请在您的视图中使用setFitsSystemWindows(false)方法(在我的情况下,对于NavigationView),以避免影响状态栏和导航栏更改.

  1. Please use setFitsSystemWindows(false) method for your view, in my case, for NavigationView, to avoid impact of status bar and navigation bar changes.

我发现NavigationView的超类ScrimInsetsFrameLayout中有OnApplyWindowInsetsListener,然后我通过使用ViewCompat.setOnApplyWindowInsetsListener(mNavigationView,null)清除了此侦听器,以避免在启用/禁用全屏时产生影响.

I found there is OnApplyWindowInsetsListener in NavigationView's super class: ScrimInsetsFrameLayout, then I clear this listener to avoid impact when full screen is enabled/disabled, by using ViewCompat.setOnApplyWindowInsetsListener(mNavigationView, null).

现在,当退出全屏显示时,NavigationView可以正常运行,希望这对您的问题有所帮助.

Now the NavigationView behaves correctly when exit full screen, hope this helps for your problem.

这篇关于Android:全屏系统可见性破坏了窗口插图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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