android冷启动的时候,如果是没做过处理的,一般是会出现短暂白屏或者黑屏才会跳到我们的第一个页面.之所以会出现这个原因是和window的背景有关,我们只需要给第一个启动的activity自定义一个theme即可,将theme的windowBackground设置为需要的图片即可.
定义一个splash.xml的drawable文件
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@mipmap/welcome_bg"
></item>
</layer-list>
这里使用layer-list是为了可以放置多张重叠图片 2. 自定义style,将背景设置为上面的xml
<style name="SplashTheme" parent="AppTheme" >
<item name="android:windowBackground">@drawable/splash</item>
</style>
3.将第一个启动的activity的theme设置为上面自定的Splashtheme即可.切记只要给第一个activity设置就好,否则会出现其他activity的跳转动画失效的现象.
转载请注明原文地址: https://ju.6miu.com/read-1308426.html