【问题标题】:After exiting fullscreen in Xamarin Forms Android app, status bar overlaps page在 Xamarin Forms Android 应用程序中退出全屏后,状态栏与页面重叠
【发布时间】:2020-12-23 14:05:57
【问题描述】:

我有一个应用程序可以在全屏(无状态栏且仅限横向)和常规(有状态栏且无方向限制)之间切换。

我正在使用服务依赖项调用带有布尔标志的 MainActivity 上的方法。

我使用了两种不同的方法来切换全屏设置:设置 Window.DecorView.SystemUiVisibility 和在 Window 上添加/清除标志。在下面的代码中,第二种方法被注释掉了:

                if (fullScreenOn)
                {
                    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(
                        SystemUiFlags.Fullscreen
                        | SystemUiFlags.HideNavigation
                        | SystemUiFlags.Immersive
                        | SystemUiFlags.ImmersiveSticky
                        | SystemUiFlags.LowProfile
                        | SystemUiFlags.LayoutStable
                        | SystemUiFlags.LayoutHideNavigation
                        | SystemUiFlags.LayoutFullscreen
                    );

                    //Window.AddFlags(WindowManagerFlags.Fullscreen);

                    RequestedOrientation = ScreenOrientation.Landscape;
                }
                else
                {
                    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(
                        SystemUiFlags.LayoutStable
                        | SystemUiFlags.LayoutHideNavigation
                        | SystemUiFlags.LayoutFullscreen
                    );

                    //Window.ClearFlags(WindowManagerFlags.Fullscreen);

                    RequestedOrientation = ScreenOrientation.Unspecified;
                }

我尝试从不同的地方调用依赖方法:OnAppearing() 和 OnDisappearing() 在全屏页面中,在所有页面中,只是在所有页面中 OnAppearing(),以及(不在同一个版本中)从我的导航打开新页面或退回到现有页面时的代码。

应用程序在正常页面中启动,并且在查看其中一个全屏页面并在状态栏返回时返回正常页面之前,它都可以正常工作,但页面使用屏幕的整个高度并重叠为结果。

还有一个令人烦恼的问题,那就是即使从一个全屏页面转到另一个页面,状态栏也会弹出和弹出。

该应用的 iOS 版本没有这些问题。显然,它在依赖方法中使用了不同的实现。

编辑

我创建了一个最小的应用程序,它重现了https://github.com/aptwebapps/StatusBarBug 的主要问题。有趣的是,它不会受到在两个全屏页面之间移动时状态栏弹出和弹出的烦恼。

【问题讨论】:

  • 你能提供代码片段让我重现吗?你说的重叠是什么意思?你是说两页吗?
  • 重叠是指视觉上的。状态栏覆盖了页面的顶部。具体来说,它覆盖了大约一半的导航栏。

标签: c# xamarin.forms xamarin.android fullscreen statusbar


【解决方案1】:

我已经测试了您的项目并复制了页面顶部的覆盖部分。

转载:

在 MainActivity 中的base.OnCreate(savedInstanceState); 之前添加以下代码。

  this.Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);

截图:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-12
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    相关资源
    最近更新 更多