如何在 xamarin Android 中隐藏系统导航栏?

How to hide system navigation bar in xamarin Android?

找不到隐藏系统导航栏的方法。我有一个包含视频的应用程序。当应用程序处于全屏模式时,我想降低系统栏,包括主页、后退和概览按钮,以便有真正的全屏体验。有人知道怎么做吗?

I have an app which has video in it and when it goes fullscreen I'd like the lower system bar (with buttons home, back, overview) to hide so there's a real fullscreen experience.

在MainActivity.cs中,您可以覆盖OnWindowFocusChanged(),使顶部状态栏和底部系统导航栏根据需要消失,以实现全屏。

  public override void OnWindowFocusChanged(bool hasFocus)
    {
        base.OnWindowFocusChanged(hasFocus);

        if (hasFocus)
        {
            var uiOptions =
              SystemUiFlags.HideNavigation |
              SystemUiFlags.LayoutHideNavigation |
              SystemUiFlags.LayoutFullscreen |
              SystemUiFlags.Fullscreen |
              SystemUiFlags.LayoutStable |
              SystemUiFlags.ImmersiveSticky;

            Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
        }
    }

我是这样做的:

SystemUiFlags hideNav = SystemUiFlags.HideNavigation;
            hideBar.Window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.HideNavigation;

但它已被弃用,所以这里有一个实际的方法:

                IWindowInsetsController insetsController = hideBar.Window.InsetsController;     //actual way to hide navBar
            if (insetsController != null)
            {
                insetsController.Hide(WindowInsets.Type.NavigationBars());
            }