前言
Android启动出现黑屏(或白屏) ,按照出现的时间不同,可以分为两种情况。
- 启动到闪屏页面(splash screnn)出现前,出现黑屏。
- 闪屏页面消失到APP首页出现之前,出现黑屏。
闪屏页面出现前
在这种情况下出现黑屏,要想做优化,只能通过修改原生代码来实现。
第一步,修改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">
闪屏页面出现后
在这种情况下出现黑屏,相对比较容易优化。
把闪屏页面消失修改为不自动消失,通过代码来延迟闪屏页面的消失。
第一步,修改config.xml中的AutoHideSplashScreen为false
<preference name="AutoHideSplashScreen" value="false" />
第二步,隐藏闪屏页面
在app.js中通过代码延时隐藏闪屏页面,避免出现黑屏
// 延迟splash screnn 隐藏时间,不然会有短暂的白屏出现
if (navigator.splashscreen) {
setTimeout(function () {
navigator.splashscreen.hide();
}, 300);
}
网友评论