图标点击启动应用的时候都有一段时间的白屏,这会给人一种卡顿的感受。注意看了下,手机上有很多应用也有这样的问题。不过微信、百度地图这些应用没有这个问题。android
解决的办法有不少,其中最简单的一种:git
咱们能够定义一个简单的主题样式,在样式中将windowBackground从新设置(android默认的主题样式将该值设置为白色,因此会出现短期的白屏)github
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> </style> <style name="Launcher" parent="AppTheme"> <item name="android:windowBackground">@drawable/window_background</item> </style> <style name="AppThemeRed" parent="AppTheme"> <item name="colorPrimary">@color/color_primary_red</item> <item name="colorPrimaryDark">@color/color_primary_red_dark</item> </style>
这里定义了一个Launcher的主题样式,咱们能够在maifest中引用该主题,这里设置的windowBackground会将全部antivity中的背景设置为指定背景。因此为了使activity中的背景恢复为默认白色,须要在activity中从新设置主题:微信
setTheme(R.style.AppThemeRed);
注意这句话应该写在super.onCreate()前面。post
背景的drawable能够是这样的:google
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"> <item android:drawable="@color/launcher_back_color"/> <item> <bitmap android:src="@mipmap/ic_launcher" android:gravity="center"/> </item> </layer-list>
具体参考:https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhdcode
项目参考:https://github.com/buobao/NiceGirl.gitxml
其余一些解决方案参考:http://saulmm.github.io/avoding-android-cold-startsip