如下有2種方式html
1 主Active中 onCreate函數裏添加代碼前端
2 config.xml文件進行配置(對經過命令行模式下cordova命令行生成的可行)android
確保本身安裝了SplashScreen插件apache
cordova plugin add org.apache.cordova.splashscreen
修改res\xml\config.xml網絡
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.SplashScreen"/>
</feature>ide
方案1函數
import android.os.Bundle; import android.view.Menu; //import android.view.MenuItem; import org.apache.cordova.*; public class MainActivity extends CordovaActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setBooleanProperty("loadInWebView", true); //啓動動畫 代碼 在loadUrl以前 super.setIntegerProperty("splashscreen", R.drawable.a); //R.drawable.a 這個說明是資源文件drawable下的文件名爲bg的資源(不寫後綴) //super.loadUrl("file:///android_asset/www/index.html"); super.loadUrl("http://192.168.55.175:5000",7000); } }
備註: drawable 是文件夾,路徑是/res/drawble/a.png優化
a是啓動圖片,建議像素爲 720*1280 放在該路徑下 這裏引用不須要擴展名動畫
方式2spa
config.xml文件添加以下代碼
<preference name="SplashScreen" value="a"/> #此節點爲啓動畫面延時單位爲毫爲,設置爲10秒(防止網絡延時,程序沒有加載完成,致使黑屏。 <preference name="SplashScreenDelay" value="10000"/>
優化:
前端index.html 頁面
除了引用 cordova.js文件
添加以下js代碼
//在啓動的頁面中加入js代碼,設備初始化後,隱藏啓動畫面 document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { navigator.splashscreen.hide(); }