Android 應用冷啟動時,需要從Application開始啟動,加載時間就會比較長,容易出現白色或黑色閃屏,觀察一下手機上一些 其他APP 比如 微信、京東等就不存在這個現象。
原因分析
分析一下原因,其實是跟閃屏Activity的主題有關,比如使用了Theme.AppCompat.Light.DarkActionBar主題的話,其中指定了windowBackground,所以背景就是白色的了。
解決方案
設置Theme
我們需要在 manifest指定SplashActivity的theme
<activity android:name=".SplashActivity" android:theme="@style/AppTheme.Splash"> ...</activity>
設置 Style 背景圖片
<style name="AppTheme.Splash" parent="AppTheme"> <item name="android:windowBackground">@mipmap/splash</item> <item name="android:windowNoTitle">true</item></style>
這個style只是用來做閃屏的主題,APP的默認主題還是使用AppTheme
這種設置后默認先是出現APP內置的閃屏圖片,然后在SplashActivity中再動態加載在線閃屏,最后進入主界面。最終實現效果與京東的APP類似。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答