Cordova设置应用图标icon和启动页面SplashScreen

Cordova通过配置CLI (config.xml) 来实现应用图标和启动展示图片页面

应用图标icon

  1. <icon src="res/icon.png" />

启动页面SplashScreen

在使用SplashScreen之前需要给项目添加splashscreen插件

  1. > cordova plugin add org.apache.cordova.splashscreen

基本示例

  1. <platform name="android">
  2. <icon src="res/android/ldpi.png" density="ldpi" />
  3. <icon src="res/android/mdpi.png" density="mdpi" />
  4. <icon src="res/android/hdpi.png" density="hdpi" />
  5. <icon src="res/android/xhdpi.png" density="xhdpi" />
  6. </platform>

目前(Cordova 3.5.0)已经支持的平台

  • android
  • ios
  • wp8
  • windows8
  • blackberry10

多平台与多分辨率

  1. <platform name="android">
  2. <!-- you can use any density that exists in the Android project -->
  3. <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi"/>
  4. <splash src="res/screen/android/splash-land-ldpi.png" density="land-ldpi"/>
  5. <splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi"/>
  6. <splash src="res/screen/android/splash-land-xhdpi.png" density="land-xhdpi"/>
  7. <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi"/>
  8. <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi"/>
  9. <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi"/>
  10. <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi"/>
  11. </platform>
  12. <platform name="ios">
  13. <!-- images are determined by width and height. The following are supported -->
  14. <splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/>
  15. <splash src="res/screen/ios/Default@2x~iphone.png" width="640" height="960"/>
  16. <splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/>
  17. <splash src="res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
  18. <splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/>
  19. <splash src="res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
  20. <splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>
  21. <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>
  22. <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>
  23. <splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/>
  24. </platform>
  25. <platform name="wp8">
  26. <!-- images are determined by width and height. The following are supported -->
  27. <splash src="res/screen/wp8/SplashScreenImage.jpg" width="768" height="1280"/>
  28. </platform>
  29. <platform name="windows8">
  30. <!-- images are determined by width and height. The following are supported -->
  31. <splash src="res/screen/windows8/splashscreen.png" width="620" height="300"/>
  32. </platform>
  33. <platform name="blackberry10">
  34. <!-- Add a rim:splash element for each resolution and locale you wish -->
  35. <!-- http://developer.blackberry.com/html5/documentation/rim_splash_element.html -->
  36. <rim:splash src="res/screen/windows8/splashscreen.png"/>
  37. </platform>
  38. <preference name="SplashScreenDelay" value="10000" />

初始化完成后隐藏Splash画面

  1. document.addEventListener("deviceready", onDeviceReady, false);
  2. function onDeviceReady() {
  3. navigator.splashscreen.hide();
  4. }

参考地址

官方说明

注意

以上图像的路径都是相对于工程根目录而非www


Related