flutter 配置 安卓、Ios启动图

android 配置启动图

launch_background.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="?android:colorBackground" />
<item>
        <bitmap
           android:gravity="fill"
            android:src="@mipmap/launch" />
    </item>
    <!-- You can insert your own image assets here -->
    <!-- <item>
        <bitmap
            android:gravity="fill"
            android:src="@mipmap/launch_image" />
    </item> -->
</layer-list>

注意:这里在drawable和drawable-v21目录中的两个文件都需要更换android:gravity="fill" 就是铺满,android:gravity="center",图片居中,通常用于 logo + 纯色背景

AndroidManifest.xml

android:theme="@style/LaunchTheme" 如下图添加位置

复制代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
 <!-- 这里必须设置 -->
    <application
        android:label="storeapp"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
             android:theme="@style/LaunchTheme" 
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

mipmap-mdpi

这几个文件内部吧launch.png图片放进去

  • 重新运行就可以了

iOS 启动页配置

iOS的启动页通常是Storyboard文件:ios/Runner/Base.lproj/LaunchScreen.storyboard

步骤

  1. 打开 ios/Runner.xcworkspace(Xcode工程)
  2. 到 LaunchScreen.storyboard 文件
  3. 你可以在Storyboard里编辑启动页的布局、图片和背景颜色
  4. 启动页的颜色也可以在 Info.plist 的 UILaunchStoryboardName 项确认为 LaunchScreen

推荐自动化方案 你也可以用Flutter插件

  • 你也可以用Flutter插件 flutter_native_splash 来自动帮你生成配置启动页。

使用示例

复制代码
安装插件
dev_dependencies:
  flutter_native_splash: ^2.2.10

yaml配置

复制代码
flutter_native_splash:
  color: "#ffffff"  # 启动页背景色(可根据图片底色自定义)
  image: assets/launch.png  # 一整张图的路径
  android: true
  ios: true
  fullscreen: true  # 推荐设置为 true,一整张图全屏展示


解构
your_project/
├── assets/
│   └── launch.png   ← 一整张启动图

在 pubspec.yaml 中声明图片资源

复制代码
flutter:
  assets:
    - assets/launch.png

运行

复制代码
flutter pub run flutter_native_splash:create
相关推荐
安和昂1 分钟前
【iOS】 Block再学习
学习·ios·cocoa
pop_xiaoli3 分钟前
OC学习—命名规范
学习·ios
婵鸣空啼3 小时前
GD图像处理与SESSiON
android
sunly_4 小时前
Flutter:导航固定背景图,滚动时导航颜色渐变
android·javascript·flutter
Digitally4 小时前
如何在没有 iTunes 的情况下备份 iPhone
ios·iphone
用户2018792831675 小时前
简单了解android.permission.MEDIA_CONTENT_CONTROL权限
android
_一条咸鱼_5 小时前
Android Runtime类卸载条件与资源回收策略(29)
android·面试·android jetpack
顾林海5 小时前
Android Bitmap治理全解析:从加载优化到泄漏防控的全生命周期管理
android·面试·性能优化
砖厂小工5 小时前
Now In Android 精讲 8 - Gradle build-logic 现代构建逻辑组织方式
android
玲小珑5 小时前
Auto.js 入门指南(八)高级控件与 UI 自动化
android·前端