VS 2019 16.11.0 Preview 1.0 - WindowInsetsControllerCompat
@jpobst As you predicted Xamarin.AndroidX.Core 1.5.0 has now been released, so I tested against the changes I made re the now closed issue xamarin/xamarin-android#5970.
In the AndroidR only version, the HideSystemUi was
Activity.Window.SetDecorFitsSystemWindows(false);
IWindowInsetsController windowInsetsController = Activity.Window.InsetsController;
windowInsetsController.Hide(WindowInsets.Type.StatusBars() | WindowInsets.Type.NavigationBars());
windowInsetsController.SystemBarsBehavior = (int)WindowInsetsControllerBehavior.ShowTransientBarsBySwipe;
For the WindowsCompat version, my initial attempt was
WindowCompat.SetDecorFitsSystemWindows(Activity.Window, false);
WindowInsetsControllerCompat windowInsetsControllerCompat = ViewCompat.GetWindowInsetsController(Activity.Window.DecorView);
windowInsetsControllerCompat.Hide(WindowInsetsCompat.Type.SystemBars() | WindowInsets.Type.NavigationBars());
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
That works on AndroidR, but fails at runtime on anything lower than AndroidR because windowInsetsControllerCompat is always null.
Is that to be expected? The Android docs state Retrieves a WindowInsetsControllerCompat of the window this view is attached to, so I assumed it would work for all BuildVersionsCodes.
To get around it I create a WindowInsetsControllerCompat in the OnResume of the Fragment.
windowInsetsControllerCompat = new WindowInsetsControllerCompat(Activity.Window, Activity.Window.DecorView);
and then just use.
WindowCompat.SetDecorFitsSystemWindows(Activity.Window, false);
windowInsetsControllerCompat.Hide(WindowInsetsCompat.Type.SystemBars() | WindowInsets.Type.NavigationBars());
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
WindowInsetsControllerCompat windowInsetsControllerCompat = ViewCompat.GetWindowInsetsController(Activity.Window.DecorView);
Appreciate your comments.
Another method I wanted to consider trying was
public static WindowInsetsControllerCompat toWindowInsetsControllerCompat(WindowInsetsController insetsController)
but it appears to be missing from Xamarin.AndroidX.Core 1.5.0
public static WindowInsetsControllerCompat toWindowInsetsControllerCompat(WindowInsetsController insetsController)
but it appears to be missing from Xamarin.AndroidX.Core 1.5.0
This seems to be available now, so it must have gotten fixed at some point since this was filed.