void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MySplashPage(),
);
}
}
class MySplashPage extends StatefulWidget {
@override
_MySplashPageState createState() => _MySplashPageState();
}
class _MySplashPageState extends State<MySplashPage> {
@override
Widget build(BuildContext context) {
return Container(
child: Image(
image: AssetImage('images/splash.png'),
fit: BoxFit.fill,
),
);
}
@override
void initState() {
// 启动的时候将屏幕设置成全屏模式
SystemChrome.setEnabledSystemUIOverlays([]);
super.initState();
// 这里进行1秒后跳转
Timer(
Duration(seconds: 1),
() => Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (BuildContext context) => MyHomePage())));
}
@override
void dispose() {
// 关闭的时候将屏幕设置成原来的状态
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
super.dispose();
}
}
<?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>
全屏显示
<bitmap android:gravity="fill" android:src="@drawable/splash" />
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<!-- 正常的状态下也是显示splash一样的状态-->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
最后官方其实有教程的
官方地址
本文地址:https://blog.csdn.net/ButtonXin/article/details/107388129
如对本文有疑问, 点击进行留言回复!!
NullPointerException: Attempt to invoke virtual method ‘android.content.res.XmlResourceParser androi
关于启动appium-desktop,报错:Cannot extract apk info using apkanalyzer. Falling back to aapt. Original ....
Gradle 发布共享库——如何通过Gradle发布Android依赖库(aar)到 jitpack 公共仓库
Gradle 发布共享库——如何通过Gradle发布java依赖库(jar)到 jitpack 公共仓库(—)
网友评论