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

如何为.NET MAUI Blazor安卓应用设置全屏启动页

.NET MAUI Blazor Android 12+ 全屏启动页解决方案

Android 12及以上版本启用了全新的SplashScreen API,旧的启动页配置方式不再完全适配,这不是MAUI的已知问题,而是需要针对性配置新的系统API来实现全屏效果。以下是具体解决步骤:

1. 创建Android 12+专属启动样式

在Platforms/Android/Resources/values-v31目录下创建styles.xml(目录不存在则手动创建),添加全屏启动屏样式:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Maui.SplashScreen" parent="Theme.Maui.SplashScreen">
    <!-- 启用全屏模式 -->
    <item name="android:windowFullscreen">true</item>
    <!-- 允许内容延伸至刘海/挖孔区域 -->
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    <!-- 按需配置启动页背景与图标 -->
    <item name="android:windowSplashScreenBackground">@color/your_splash_background</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/your_splash_icon</item>
  </style>
</resources>

2. 关联启动Activity与新样式

打开Platforms/Android/AndroidManifest.xml,将MainActivity的主题指定为上述样式:

<activity android:name=".MainActivity"
          android:exported="true"
          android:theme="@style/Maui.SplashScreen">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

3. 优化启动页资源适配

  • 若使用PNG图片,需将不同密度版本(如xxxhdpi、xxhdpi等)放入对应drawable-xxxhdpi目录,避免拉伸或显示不全。
  • 若使用SVG,确认项目csproj中的MauiSplashScreen配置正确,MAUI会自动生成适配各密度的资源:
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#FFFFFF" />

4. 清理旧冲突配置

如果之前在MainActivity.cs的OnCreate方法中通过Window.SetFlags等方式设置全屏,建议移除这些代码,避免与新API冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 19:55:57