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

Android 12环境下MAUI应用Splashscreen不显示问题求助

Android 12真机上.NET MAUI启动屏不显示的解决方案

针对Android 12(API 31+)真机上MAUI启动屏不显示的问题,以下是经过验证的解决步骤:

1. 修正AndroidManifest.xml配置

Android 12引入了全新的SplashScreen API,需在Platforms/Android/AndroidManifest.xml中完成对应配置:

<application ...>
  <!-- 指定启动屏资源 -->
  <meta-data
      android:name="android.splashscreen.drawable"
      android:resource="@drawable/maui_splash" />
  
  <!-- 确保MainActivity主题关联启动屏样式 -->
  <activity
      android:name=".MainActivity"
      android:exported="true"
      android:theme="@style/Maui.SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
</application>

2. 调整启动屏样式与资源文件

在Platforms/Android/Resources/values/styles.xml中,确保启动屏主题正确继承Android 12的SplashScreen主题:

<style name="Maui.SplashTheme" parent="Theme.SplashScreen">
  <!-- 设置启动屏背景色 -->
  <item name="android:windowSplashScreenBackground">@color/maui_splash_color</item>
  <!-- 设置启动屏图标 -->
  <item name="android:windowSplashScreenAnimatedIcon">@drawable/your_splash_icon</item>
</style>

若使用layer-list格式的maui_splash.xml,需适配Android 12的资源规则,调整图片尺寸与缩放方式:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    <item android:drawable="@color/maui_splash_color" />
    <item
        android:width="192dp"
        android:height="192dp"
        android:gravity="center">
        <bitmap
            android:src="@drawable/your_splash_image"
            android:scaleType="centerInside"
            android:mipMap="true"/>
    </item>
</layer-list>

注意:Android 12启动屏图标建议尺寸为192x192dp;若使用SVG资源,需确保文件放在drawable根目录,而非仅兼容高版本的drawable-v24目录。

3. 检查MAUI项目配置

在项目.csproj文件中,确认启动屏资源被正确打包:

<ItemGroup>
  <MauiSplashScreen Include="Resources\Splash\splash.png" >
    <TargetPath>Resources\drawable\your_splash_image.png</TargetPath>
    <Color>#FFFFFF</Color> <!-- 对应colors.xml中的maui_splash_color -->
  </MauiSplashScreen>
</ItemGroup>

4. 清理缓存并重装应用

  • 删除项目的bin、obj文件夹,执行清理解决方案后重新生成
  • 在真机上彻底卸载旧版本应用,再安装新编译的APK

常见排查点

  • 启动屏图片文件名只能用小写字母、数字和下划线,禁止大写或特殊字符
  • 检查colors.xml中是否已定义maui_splash_color
  • 若仍不显示,尝试将SVG替换为简单PNG图片,排除矢量图兼容性问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 23:21:01