解決APP啟動白屏或者黑屏閃現的問題
阿新 • • 發佈:2019-01-09
解決辦法,自定義Theme,有兩種方法,第一種Theme就是設定一張背景圖。當程式啟動時,首先顯示這張背景圖,避免出現黑屏。第二種Theme是把樣式設定為透明,程式啟動後不會黑屏而是整個透明瞭,等到介面初始化完才一次性顯示出來。
//1、設定背景圖Theme
<style name="Theme.AppStartLoad" parent="android:Theme">
<item name="android:windowBackground">@drawable/ipod_bg</item>
<item name="android:windowNoTitle" >true</item>
</style>
//2、設定透明Theme
<style name="Theme.AppStartLoadTranslucent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
兩種方式的優缺點:
Theme1 程式啟動快,介面先顯示背景圖,然後再重新整理其他介面控制元件。給人重新整理不同步感覺,直觀現象就是顯示可能會有錯位偏移。
Theme2 給人程式啟動慢感覺,介面一次性刷出來,重新整理同步,直觀感覺很連貫。(推薦)
AndroidManifest.xml配置:
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppStartLoadTranslucent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>