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

如何使用MAUI在iOS和Android上创建全屏启动页

MAUI全屏图文启动页解决方案

一、核心思路

放弃MAUI默认的启动图标自动生成逻辑,直接针对Android和iOS平台做原生启动页自定义,实现全屏展示图片+文字的效果,彻底解决平台适配问题。

二、Android端(解决圆形图标显示问题)

  1. 自定义启动页布局
    • 打开Platforms/Android/Resources/layout/launch_screen.xml(没有就新建),写入全屏布局代码:
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:gravity="center"
          android:background="#FFFFFF"> <!-- 可替换为你的背景色 -->
          
          <!-- 启动页主图 -->
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/splash_main" /> <!-- 替换为你的图片文件名 -->
          
          <!-- 底部说明文字 -->
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="32dp"
              android:text="你的应用名称"
              android:textSize="20sp"
              android:textColor="#333333" />
      </LinearLayout>
      
    • 将你的启动页图片放入Platforms/Android/Resources/drawable目录(建议同时放入drawable-xhdpi、drawable-xxhdpi等分辨率子目录适配不同设备)。
  2. 修改主题与清单配置
    • 打开Platforms/Android/AndroidManifest.xml,将MainActivity的主题替换为自定义主题:
      <activity android:name=".MainActivity"
                android:theme="@style/SplashTheme">
      
    • 在Resources/values/styles.xml中添加SplashTheme:
      <style name="SplashTheme" parent="Theme.Maui.NoActionBar">
          <item name="android:windowBackground">@drawable/launch_screen</item>
          <item name="android:windowFullscreen">true</item> <!-- 强制全屏 -->
          <item name="android:windowContentOverlay">@null</item>
      </style>
      
    • 删除清单中所有指向mipmap/ic_launcher的配置,避免系统自动裁剪圆形图标。

三、iOS端(解决UI适配问题)

  1. 编辑Launch Screen Storyboard
    • 打开Platforms/iOS/LaunchScreen.storyboard,删除默认控件,搭建全屏布局:
      • 添加一个UIView作为容器,设置约束使其铺满整个屏幕。
      • 添加UIImageView,导入你的启动页图片,设置居中约束并调整合适大小。
      • 添加UILabel,设置文字、字体、颜色,约束在图片下方居中。
    • 所有控件使用相对约束(比如基于Safe Area的间距),确保适配不同屏幕尺寸。
  2. 配置Info.plist
    • 打开Platforms/iOS/Info.plist,确认UILaunchStoryboardName值为LaunchScreen,删除旧的UILaunchImages配置(如果存在)。
  3. 开启全屏显示
    • 在Info.plist中添加以下配置隐藏状态栏:
      <key>UIStatusBarHidden</key>
      <true/>
      <key>UIViewControllerBasedStatusBarAppearance</key>
      <false/>
      

四、MAUI通用过渡配置

在MauiProgram.cs中添加生命周期配置,保证启动页到主页面的过渡平滑:

builder.ConfigureLifecycleEvents(events =>
{
#if ANDROID
    events.AddAndroid(android => android
        .OnCreate((activity, bundle) =>
        {
            // 可在这里设置启动页停留时长,或直接过渡
        }));
#endif
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 16:52:21