Flutter Android项目启动白屏问题
白屏现象
首先,我们使用Android Studio创建一个Flutter项目。运行项目,我们先会看到先闪过一个白屏,然后再进入计数器页面。
那么问题来了,为什么是白屏,而不是黑屏或者其他颜色呢?
我们打开android项目,打开AndroidManifest.xml
可以看到配置启动的主题@style/LaunchTheme
,点击打开styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
点击@drawable/launch_background
打开launch_background.xml
,可以看到设置的背景为white。
<?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:src="https://juejin.cn/post/@mipmap/launch_image" />
</item> -->
</layer-list>
解决方式
我们以京东APP为例,通过解压后,找到启动图uh.9.png
,该图不能直接使用,将图片拖入绘图后保存使用。
可以看到图片尺寸为718*1278,我们在res
目录下创建drawable-xhdpi
文件夹
使用layer-list
使用截图软件,截取启动图中间图片和底部的图片放入drawable-xhdpi
,吸取背景颜色#FA2B18
修改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>
<shape>
<solid android:color="#FA2B18" />
</shape>
</item>
<item android:bottom="100dp">
<bitmap
android:gravity="center"
android:src="@drawable/center" />
</item>
<item android:bottom="30dp">
<bitmap
android:gravity="bottom"
android:src="@drawable/bottom" />
</item>
</layer-list>
效果
使用.9图
将完整图launch_image.png
片放入drawable-xhdpi
,点击右键,弹窗选择Create 9-Path file
,创建launch_image.9.png
,然后删除旧的图片,只保留.9图。
绘制原则
- 上边左右各绘制1px,距离边缘至少1px
- 左边上下绘制200px,距离边缘至少1px(取200px的原因:当屏幕显示导航栏时,图片显示的高度变小,可以上下减小图片高度,防止变形)
直接修改styles.xml
主题中的背景使用.9图
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_image</item>
</style>
</resources>
效果
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgechai
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01