flutter Splash启动页(闪屏)页面解决方案实战

1.下载插件

pubspec.yaml 文件中加入该flutter_splash_screen: ^0.1.0

2.修改MainActivity.java
路径:android\app\src\main\java\com\example\ganxin\MainActivity.java
package com.example.XXX;
import android.os.Bundle;
import io.flutter.embedding.android.FlutterActivity;
//导入我们引入的第三方框架
import org.devio.flutter.splashscreen.SplashScreen;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.engine.FlutterEngine;
import androidx.annotation.NonNull;
public class MainActivity extends FlutterActivity {
    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
      GeneratedPluginRegistrant.registerWith(flutterEngine);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      //在此调用,实现引导页屏幕的显示
      SplashScreen.show(this, true);//这行很重要
      super.onCreate(savedInstanceState);
    }
}
3.新增drawable目录 并且在里面新建文件launch_background.xml
路径:android\app\src\main\res\drawable

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" />
</layer-list>
4.styles.xml文件修改

路径:
android\app\src\main\res\values\styles.xml

代码块:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:windowIsTranslucent">true</item>//加这一行
    </style>
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@android:color/white</item>
    </style>
</resources>
5.新增 colors.xml文件

路径:
android\app\src\main\res\values\colors.xml
代码块:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--状态栏的颜色-->
    <color name="primary_dark">#000000</color>
</resources>
6.新增 layout文件夹 并新增文件

路径:
android\app\src\main\res\layout\launch_screen.xml
代码块:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--launch_icon是我们启动页的名字-->
    <ImageView android:layout_width="match_parent" android:layout_height="match_parent" 
        android:src="@drawable/splash_bg" android:scaleType="centerCrop" />//splash_bg就是你需要展示的启动页图片
</RelativeLayout>
7.main.dart 修改

引入插件:
import ‘package:flutter_splash_screen/flutter_splash_screen.dart’;

  @override
  void initState() {
    super.initState();
    hideScreen();
  }

  ///hide your splash screen
  Future<void> hideScreen() async {
    Future.delayed(Duration(milliseconds: 3600), () {
      FlutterSplashScreen.hide();
    });
  }

完毕,此时可以测试查看。。。。。。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

托马斯的冰淇淋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值