前言
Android啟動出現(xiàn)黑屏(或白屏) 涉兽,按照出現(xiàn)的時間不同,可以分為兩種情況脆侮。
- 啟動到閃屏頁面(splash screnn)出現(xiàn)前瞎领,出現(xiàn)黑屏蔓榄。
- 閃屏頁面消失到APP首頁出現(xiàn)之前,出現(xiàn)黑屏默刚。
閃屏頁面出現(xiàn)前
在這種情況下出現(xiàn)黑屏甥郑,要想做優(yōu)化,只能通過修改原生代碼來實現(xiàn)荤西。
第一步澜搅,修改app/res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo.Light"></style>
<style name="Theme.AppStartLoadTranslucent" parent="android:Theme">
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowDisablePreview">true</item>
</style>
</resources>
第二步伍俘,修改app/manifests/AndroidManifest.xml
修改MainActivity的theme為 "@style/Theme.AppStartLoadTranslucent"
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@style/Theme.AppStartLoadTranslucent" android:windowSoftInputMode="adjustResize">
閃屏頁面出現(xiàn)后
在這種情況下出現(xiàn)黑屏,相對比較容易優(yōu)化勉躺。
把閃屏頁面消失修改為不自動消失癌瘾,通過代碼來延遲閃屏頁面的消失。
第一步饵溅,修改config.xml中的AutoHideSplashScreen為false
<preference name="AutoHideSplashScreen" value="false" />
第二步妨退,隱藏閃屏頁面
在app.js中通過代碼延時隱藏閃屏頁面,避免出現(xiàn)黑屏
// 延遲splash screnn 隱藏時間蜕企,不然會有短暫的白屏出現(xiàn)
if (navigator.splashscreen) {
setTimeout(function () {
navigator.splashscreen.hide();
}, 300);
}