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

Xamarin Shell实现谷歌地图式全屏(保留状态栏)方案问询

实现Xamarin Shell全屏显示(不隐藏状态栏,类似谷歌地图效果)

Android平台完善方案

1. 基础全屏配置(你已实现的代码)

在MainActivity的OnCreate方法中添加以下代码,让内容延伸至状态栏下方,并将状态栏设为透明:

Window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
Window.ClearFlags(WindowManagerFlags.TranslucentStatus);            
Window.SetStatusBarColor(Android.Graphics.Color.Transparent);

2. 修改状态栏图标/文字颜色

根据Android版本差异,分两种方式处理:

  • Android 11(API 30)及以上:使用WindowInsetsController
if (Build.VERSION.SdkInt >= BuildVersionCodes.R)
{
    Window.InsetsController?.SetSystemBarsAppearance((int)WindowInsetsAppearance.LightStatusBars, (int)WindowInsetsAppearance.LightStatusBars);
}
  • Android 6.0(API 23)至Android 10(API 29):使用SystemUiVisibility
else if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
    Window.DecorView.SystemUiVisibility = StatusBarVisibility.LightStatusBar;
}

说明:LightStatusBars会让状态栏图标/文字变为深色,若需要浅色图标,可移除该标记(对应深色状态栏场景)。

iOS平台实现方案

1. 配置Info.plist

先在Info.plist中添加以下配置,确保状态栏样式可自定义:

<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

2. 在AppDelegate中设置全局样式

在AppDelegate的FinishedLaunching方法中,添加以下代码实现全屏+透明状态栏:

// 设置导航栏透明
UINavigationBar.Appearance.Translucent = true;
UINavigationBar.Appearance.BarTintColor = UIColor.Clear;
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.BackgroundImage = new UIImage();

// 设置状态栏样式(根据页面背景色选择:LightContent为浅色图标,Default为深色)
UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);

3. 确保内容延伸至状态栏下方

如果页面内容未自动延伸,可在对应ContentPage的代码后台添加:

protected override void OnAppearing()
{
    base.OnAppearing();
    // 隐藏默认导航栏(若使用Shell自带导航)
    if (NavigationPage.GetHasNavigationBar(this))
    {
        NavigationPage.SetHasNavigationBar(this, false);
    }
    // 取消顶部内边距,让内容顶到状态栏下方
    if (Device.RuntimePlatform == Device.iOS)
    {
        this.Padding = new Thickness(0);
    }
}

说明:若使用Shell TabBar,可通过Shell.TabBarBackgroundColor设为透明、Shell.TabBarTranslucent设为true,保持整体全屏风格。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 15:45:30