Reputation: 1
I have implemented full screen immersive launch settings on my app and tested with multiple devices and API levels. The settings that I enabled will hide the navigation bar and only show when the user swipes down from the top edge of the screen. But I am getting varying results across different devices.
The fullscreen immersive settings are not active when apps on API <30 are launched, but when I press the home screen and then resume the app the navbar does become hidden and shows from swipe down (the intended result).
I have used multiple ways to enter the app into full screen mode and all of the methods I tried work on API >= 30 but do not work on API <30
These are some examples of settings that I have tried on each device:
SOLUTION 1
private void SetWindowLayout()
{
WindowCompat.SetDecorFitsSystemWindows(Window, false);
WindowInsetsControllerCompat windowInsetsControllerCompat = new WindowInsetsControllerCompat(Window, Window.DecorView);
windowInsetsControllerCompat.Hide(WindowInsetsCompat.Type.SystemBars() | WindowInsetsCompat.Type.NavigationBars());
windowInsetsControllerCompat.Hide(WindowInsetsCompat.Type.Ime());
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
}
SOLUTION 2
private void SetWindowLayout()
{
Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.Fullscreen |
SystemUiFlags.HideNavigation |
SystemUiFlags.Immersive |
SystemUiFlags.ImmersiveSticky |
SystemUiFlags.LayoutHideNavigation |
SystemUiFlags.LayoutStable |
SystemUiFlags.LowProfile);
}
SOLUTION 3
private void SetWindowLayout()
{
IWindowInsetsController winController = Window.InsetsController;
Window.SetDecorFitsSystemWindows(false);
Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
if (winController != null)
{
winController.Hide(WindowInsets.Type.Ime());
winController.Hide(WindowInsets.Type.NavigationBars());
}
}
I call SetWindowLayout() in the OnCreate, OnResume, OnStart, and OnWindowFocusChanged as seen below
private Game1 _game;
private View _view;
protected override void OnCreate(Bundle bundle)
{
Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
Window.Attributes.PreferredRefreshRate = 60;
base.OnCreate(bundle);
_game = new Game1();
_view = _game.Services.GetService(typeof(View)) as View;
SetContentView(_view);
_game.Run();
SetWindowLayout();
}
public override void OnWindowFocusChanged(bool hasFocus)
{
base.OnWindowFocusChanged(hasFocus);
if (hasFocus)
{
SetWindowLayout();
}
}
protected override void OnStart()
{
SetWindowLayout();
base.OnStart();
}
protected override void OnResume()
{
SetWindowLayout();
base.OnResume();
}
The screenshots posted below show what happens entirely on a device running on API 29, there are 2 screenshots of the app when it is first launched and not hiding the nav bar correctly and showing that a single tap near the top of the screen will keep dropping the nav bar.
Then there are 2 screenshots after I press the home button and resume the app, and the nav bar is now doing the correct thing and will stay hidden until a down-swipe occurs.
All of the solutions I used give the same results on API < 30 but when I use API 30+ it works as soon as the app first launches and doesnt need the app to be resumed to work properly.
screenshots of correct vs incorrect results
Upvotes: 0
Views: 49