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

问题描述 投票:0回答:3

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

xamarin.android
3个回答
0
投票

我有一个包含视频的应用程序,当它全屏显示时,我希望隐藏下部系统栏(带有主页、后退、概览按钮),以便获得真正的全屏体验。

在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;
        }
    }

0
投票

我使用以下代码隐藏导航并将应用程序显示为全屏。

MainActivity.cs
文件:

        protected override void OnCreate(Bundle? savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            // to hide the navigation bar
            decorview = Window.DecorView;
            decorview.ViewTreeObserver.AddOnGlobalLayoutListener(new mOnGlobalLayoutListener());
        }

        public static int screenheight;
        public static View decorview;
        public class mOnGlobalLayoutListener : Java.Lang.Object, IOnGlobalLayoutListener
        {
            public void OnGlobalLayout()
            {
                Rect r = new Rect();
                var keypadHeight = MainActivity.screenheight - r.Bottom;
                if (keypadHeight <= MainActivity.screenheight * 0.15)
                {
                    var uiOptions =
                        SystemUiFlags.HideNavigation |
                        SystemUiFlags.LayoutHideNavigation |
                        SystemUiFlags.LayoutFullscreen |
                        SystemUiFlags.Fullscreen |
                        SystemUiFlags.LayoutStable |
                        SystemUiFlags.ImmersiveSticky;

                    MainActivity.decorview.SystemUiVisibility = (StatusBarVisibility)uiOptions;
                }
            }
        }


-1
投票

我是这样做的:

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());
            }
© www.soinside.com 2019 - 2024. All rights reserved.