最近在研究使用app的过程中发现有的app首次启动的时候会有短暂的白屏,而有的app则不会出现这样的情况,起初我以为是手机的问题,但是我换了几个手机进行测试仍然会出现这样的状况,当然出现白屏给给用户的体验肯定是不友好的
第一种方法:针对出现白屏,黑屏的现象可以直接干掉,
1.定义一个style:
<style name="AppTheme.Launcher">
<!--关闭启动窗口-->
<item name="android:windowDisablePreview">true</item>
</style>
2.只需要在启动页面引用:
<activity android:name=".MainActivity"
android:theme="@style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3.最后在MainActivity恢复正常主题:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppTheme);//恢复正常主题
setContentView(R.layout.activity_main);
}
这样启动app没有白屏,但是会出现点击桌面图标而半天没有反应的现象,显然不好,很多app把这个闪屏当做一个广告,品牌的宣传页面
第二种:其实Google针对App闪屏,也给出了非常详细的设计定义
品牌展示:屏幕提供短暂的品牌曝光,定义一个drawable/branded_launch_screens作为背景:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--黑色背景颜色-->
<item android:drawable="@android:color/black"/>
<!--产品logo-->
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
<!--右上角的图标元素-->
<item>
<bitmap
android:gravity="top|right"
android:src="@mipmap/ic_launcher"/>
</item>
<!--最下面的文字-->
<item android:bottom="50dp">
<bitmap
android:gravity="bottom"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
然后定义一个style:
<style name="AppTheme.Launcher2">
<item name="android:windowBackground">@drawable/branded_launch_screens</item>
</style>