Cordova 3.x Basics (2)-app icon and start Page SplashScreen

Source: Internet
Author: User
Tags imagemagick

label:

Original: http://rensanning.iteye.com/blog/2017380

The latest version of Cordova CLI already supports configuring <splash> and <icon>, CB-2606, CB-3571 Add support for <icon>, <splash> in config.xml. Set as follows:

Xml code
<platform name="android">
    <icon src="res/android/icon-36-ldpi.png" density="ldpi" />
    <splash src="res/android/screen-xhdpi-portrait.png" density="port-xhdpi"/>
</platform>

For details, please refer to the official document: Icons and Splash Screens

If you have ImageMagick installed locally, the CLI will also automatically call ImageMagick to make images of different sizes.
have to be aware of is: 
(1) The path of the image is relative to the project root directory not based on www
(2) Do not confuse the settings of PhoneGap CLI
=========================================================== ========


(1) Create to like

Take Android as an example:

Icon image:

Www/res/icon/android/icon-36-ldpi.png - 36px x 36px
Www/res/icon/android/icon-48-mdpi.png - 48px x 48px
Www/res/icon/android/icon-72-hdpi.png - 72px x 72px
Www/res/icon/android/icon-96-xhdpi.png - 96px x 96px

Splashscreen image:

Www/res/screen/android/screen-ldpi-landscape.png - 320px x 200px
Www/res/screen/android/screen-mdpi-landscape.png - 480px x 320px
Www/res/screen/android/screen-hdpi-landscape.png - 800px x 480px
Www/res/screen/android/screen-xhdpi-landscape.png - 1280px x 720px
Www/res/screen/android/screen-ldpi-portrait.png - 200px x 320px
Www/res/screen/android/screen-mdpi-portrait.png - 320px x 480px
Www/res/screen/android/screen-hdpi-portrait.png - 480px x 800px
Www/res/screen/android/screen-xhdpi-portrait.png - 720px x 1280px

(2) Add a splashscreen plugin to the project

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


(3) Configure config.xml

Xml code
<preference name="SplashScreen" value="splash" /> <!-- File name without suffix png, default is screen-->
<preference name="SplashScreenDelay" value="10000" /> <!-- Splash display time, the default is 3000ms-->
  
<feature name="SplashScreen">
  <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>


Compared to setting the delay time in config.xml, you should hide the Splash screen (index.html) after the device initialization is complete.

Js code
document.addEventListener("deviceready", onDeviceReady, false);
Function onDeviceReady() {
  Navigator.splashscreen.hide();
}


(4) Copy file
Phonegap can configure icon and splash in config.xml, but cordova does not support it. You need to copy the file after cordova build, or you can create it by creating a hook.
***phonegap configuration is also limited to the remote build when Phonegap Build works, local build does not work, you need to manually handle. Refer here.

Icon.png:
Copy the file under www/res/icon/android to the corresponding platforms/android/res/drawable*/.

Splash.png:
Copy the file under www/res/screen/android to the corresponding platforms/android/res/drawable*/.

Start "cordova emulate android" after you finish.

Phonegap config.xml

Xml code
<!-- Define app icon for each platform. -->
<icon src="icon.png" />
<icon src="res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:density="ldpi" />
<icon src="res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:density="mdpi" />
<icon src="res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:density="hdpi" />
<icon src="res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:density="xhdpi" />
<icon src="res/icon/blackberry/icon-80.png" gap:platform="blackberry" />
<icon src="res/icon/blackberry/icon-80.png" gap:platform="blackberry" gap:state="hover"/>
<icon src="res/icon/ios/icon-57.png" gap:platform="ios" width="57" height="57" />
<icon src="res/icon/ios/icon-72.png" gap:platform="ios" width="72" height="72" />
<icon src="res/icon/ios/icon-57-2x.png" gap:platform="ios" width="114" height="114" />
<icon src="res/icon/ios/icon-72-2x.png" gap:platform="ios" width="144" height="144" />
<icon src="res/icon/webos/icon-64.png" gap:platform="webos" />
<icon src="res/icon/windows-phone/icon-48.png" gap:platform="winphone" />
<icon src="res/icon/windows-phone/icon-173.png" gap:platform="winphone" gap:role="background" />
  
<!-- Define app splash screen for each platform. -->
<gap:splash src="res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:density="ldpi" />
<gap:splash src="res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:density="mdpi" />
<gap:splash src="res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:density="hdpi" />
<gap:splash src="res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:density="xhdpi" />
<gap:splash src="res/screen/blackberry/screen-225.png" gap:platform="blackberry" />
<gap:splash src="res/screen/ios/screen-iphone-portrait.png" gap:platform="ios" width="320" height="480" />
<gap:splash src="res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios" width="640" height="960" />
<gap:splash src="res/screen/ios/screen-ipad-portrait.png" gap:platform="ios" width="768" height="1024" />
<gap:splash src="res/screen/ios/screen-ipad-landscape.png" gap:platform="ios" width="1024" height="768" />
<gap:splash src="res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone" />
Cordova 3.x Basics (2) -- App icon icon and launch page SplashScreen


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.