You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级到.NET 10后Android 15上AppFlyout菜单覆盖状态栏的问题咨询

.NET 10 MAUI Android 15 解决Flyout覆盖状态栏问题

针对你升级到.NET 10后,Android 15上AppFlyout覆盖状态栏的问题,完全可以通过动态计算状态栏高度替代硬编码边距,具体实现步骤如下:

1. 在Android平台实现状态栏高度获取方法

在MAUI项目的Platforms/Android目录下,创建工具类PlatformHelper.cs,实现兼容不同Android版本的状态栏高度获取逻辑:

using Android.App;
using Android.OS;
using Android.Content.Res;

namespace YourAppNamespace.Platforms.Android;

public static class PlatformHelper
{
    public static int GetStatusBarHeight()
    {
        int statusBarHeight = 0;
        // 优先通过系统资源获取
        int resourceId = Application.Context.Resources.GetIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0)
        {
            statusBarHeight = Application.Context.Resources.GetDimensionPixelSize(resourceId);
        }
        // Android 11及以上版本用WindowInsets获取更准确数值
        else if (Build.VERSION.SdkInt >= BuildVersionCodes.R)
        {
            var currentActivity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
            if (currentActivity?.Window != null)
            {
                var insets = currentActivity.Window.InsetsController.GetInsets(WindowInsets.Type.StatusBars());
                statusBarHeight = insets.Top;
            }
        }
        return statusBarHeight;
    }
}

2. 在Flyout中动态设置顶部内边距

打开AppFlyout的代码后台文件(如AppFlyout.xaml.cs),在OnAppearing方法中针对Android平台设置侧边栏内容的顶部内边距,让菜单避开状态栏:

using YourAppNamespace.Platforms.Android;

namespace YourAppNamespace;

public partial class AppFlyout : FlyoutPage
{
    public AppFlyout()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

#if ANDROID
        int statusBarHeight = PlatformHelper.GetStatusBarHeight();
        // 替换为你Flyout侧边栏的根布局控件名
        FlyoutRootLayout.Padding = new Thickness(0, statusBarHeight, 0, 0);
#endif
    }
}

补充说明

  • 避免硬编码数值,不同Android设备(包括Android 15机型)的状态栏高度存在差异,动态获取能保证全机型适配。
  • 若Flyout布局结构不同,只需将内边距设置到侧边栏的根布局控件上,确保菜单内容从状态栏下方开始渲染。

内容的提问来源于stack exchange,提问作者user3017691

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 00:45:00