Flutter入门系列-App闪屏页设置

在Flutter项目中,好像之前的版本设置闪屏页都比较复杂,但是现在比较简单了,可以在 android 项目的清单文件中进行如下设置:

<activity
    android:name=".MainActivity"
    android:launchMode="singleTop"
    android:theme="@style/LaunchTheme"
    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"
      />
    <!-- Displays an Android View that continues showing the launch screen
          Drawable until Flutter paints its first frame, then this splash
          screen fades out. A splash screen is useful to avoid any visual
          gap between the end of Android's launch screen and the painting of
          Flutter's first frame. -->
    <meta-data
      android:name="io.flutter.embedding.android.SplashScreenDrawable"
      android:resource="@drawable/launch_background"
      />
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

从上面的介绍来可以看出,在 SplashScreenDrawable 的所属 meta-data 中可以对闪屏页的图片进行设置,修改 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:color/white" />

    <!-- You can insert your own image assets here -->
    <!--顶部 -->
    <item>
        <bitmap
            android:gravity="center"
            android:scaleType="center"
            android:src="@mipmap/ic_launcher" />
    </item>
   <!-- 底部-->
   <item android:bottom="65dp">
        <bitmap
            android:gravity="bottom|center_horizontal"
            android:scaleType="center"
            android:src="@mipmap/screen_txt"
            />
   </item>
</layer-list>

注意:这里的 launch_background.xml 修改涉及到两处,一处是在drawable目录下 ,一处是在drawable-v21目录下,否则不出效果。

修改完成之后,启动可以看出效果如下:

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值