1、启动白屏解决方法,在欢迎界面Activity 主题添加背景
方法一:
<style name="AppTheme.StartingWindowTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/white</item>
<item name="android:windowBackground">@mipmap/fantastia_startpage</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textAllCaps">false</item>
<item name="android:navigationBarColor">@color/white</item>
</style>
方法二:
<!--关闭启动窗口-->
<item name="android:windowDisablePreview">true</item>
最后在MainActivity恢复正常主题:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_main);
}
2、解决首次启动程序白屏时间过长
造成原因:由于gradle插件问题,如果是2.0.0不会有这个问题
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
3、看到见面再开始一系列的耗时操
第一种写法:直接PostDelay 300ms.
myHandler.postDelayed(mLoadingRunnable, DEALY_TIME);
第二种写法:优化的DelayLoad
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
myHandler.post(mLoadingRunnable);
}
});
极力推荐用第二种,在窗口完成以后进行加载,这里面的run方法是在onResume之后运行的。