Flutter项目中设置安卓启动页

AndroidManifest.xml

设置 android:theme="@style/LaunchTheme"

xml 复制代码
<application
        android:label="@string/app_name"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher"
        android:theme="@style/LaunchTheme">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

styles.xml

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
    <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

launch_background.xml

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap android:src="@drawable/launch_image" />
    </item>
    <item
        android:width="65dp"
        android:height="326dp"
        android:gravity="center_horizontal|clip_vertical"
        android:top="145dp">
        <bitmap android:src="@drawable/ver6_bg_word" />
    </item>
    <item
        android:width="209dp"
        android:height="66dp"
        android:bottom="18dp"
        android:gravity="bottom|center_horizontal">
        <bitmap android:src="@drawable/ver6_prod_logo" />
    </item>
</layer-list

项目结构:

iOS LaunchScreen.storyboard 的使用和适配

修复项目中的警告⚠️

dart fix --apply --code=unused_import

dart fix --apply --code=use_key_in_widget_constructors

相关推荐
弥巷10 小时前
【Android】Android内存缓存LruCache与DiskLruCache的使用及实现原理
android·java
fool_hungry11 小时前
Android MotionEvent ACTION_OUTSIDE 详细解释
android
下位子12 小时前
『OpenGL学习滤镜相机』- Day8: 多重纹理与混合
android·opengl
TeleostNaCl12 小时前
解决在 Android 使用 hierynomus/smbj 库时上传和下载文件较慢的问题
android·经验分享
峰哥的Android进阶之路12 小时前
handler机制原理面试总结
android·面试
雨白12 小时前
让代码更清晰:Android 中的 MVC、MVP 与 MVVM
android·mvc·mvvm
魑魅魍魉都是鬼12 小时前
不练不熟,不写就忘 之 compose 之 动画之 animateSizeAsState动画练习
android·compose
一只柠檬新13 小时前
当AI开始读源码,调Bug这件事彻底变了
android·人工智能·ai编程
正经教主13 小时前
【App开发】手机投屏的几种方式(含QtScrcpy)- Android 开发新人指南
android·智能手机
-指短琴长-15 小时前
MySQL快速入门——内置函数
android·数据库·mysql