原因分析:应用点击后,会先打开入口activity,而对应应用还没有启动,系统会为该应用创建一个进程,而创建和初始化进程需要时间,该过程中应用程序无法显示,所以会出现短暂的黑屏或白屏
解决办法:在应用初始化完成前显示临时图片
具体做法:设置主题
1.入口页设置主题图片
a.为启动页设置主题
<activity
android:name=".activity.HnSplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
b.在Style中为WindowBackground设置一张背景图。
<!--// Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/main_color</item>
<item name="colorPrimaryDark">@color/main_color</item>
<item name="colorAccent">@color/main_color</item>
</style>
<!--启动页背景-->
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/start</item>
</style>
解决方式之使用颜色
为启动页设置主题
<activity
android:name=".activity.HnSplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
在Style中为WindowBackground设置颜色。
<!-- 防止欢迎页白屏或者黑屏,设置图片 -->
<style name="SplashTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowFullscreen">true</item>
<item name="windowNoTitle">true</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 背景颜色 -->
<item android:drawable="@color/green" /> <item>
<!-- 图片 -->
<bitmap android:gravity="center" android:src="@drawable/icon_welcome" /> </item>
</layer-list>
参考链接:https://blog.csdn.net/meijing11/article/details/79245372