Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Fullscreen system visibility screws up window insets

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)

enter image description here

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

like image 447
M Dapp Avatar asked Nov 09 '22 23:11

M Dapp


1 Answers

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.

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

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

  2. 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).

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

like image 88
Hexise Avatar answered Nov 15 '22 11:11

Hexise