cordova啓動頁面和圖標的設置

原文地址css

1、config.xml配置

在cordova5.0版本之後,須要安裝cordova-plugin-splashscreen插件之後才能修改和設置App的啓動頁面。android

安裝splashscreen插件:

cordova plugin add cordova-plugin-splashscreen
或
cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git

基本配置

而後在你的config.xml文件中,添加如下代碼ios

<platform name="android">  
    <icon density="ldpi" src="res/icon/android/drawable-ldpi/icon.png" />
    <icon density="mdpi" src="res/icon/android/drawable-mdpi/icon.png" />
    <icon density="hdpi" src="res/icon/android/drawable-hdpi/icon.png" />
    <icon density="xhdpi" src="res/icon/android/drawable-xhdpi/icon.png" />
    <icon density="xxhdpi" src="res/icon/android/drawable-xxhdpi/icon.png" />
    <!-- 如下是歡迎頁面,可根據須要進行添加 -->
    <splash density="land-hdpi" src="res/screen/android/splash-land-hdpi.png" />  
    <splash density="land-ldpi" src="res/screen/android/splash-land-ldpi.png" />  
    <splash density="land-mdpi" src="res/screen/android/splash-land-mdpi.png" />  
    <splash density="land-xhdpi" src="res/screen/android/splash-land-xhdpi.png" />  
    <splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />  
    <splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />  
    <splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />  
    <splash density="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />  
</platform>  
<platform name="ios">  
    <!-- iOS 8.0+ -->  
    <!-- iPhone 6 Plus  -->  
    <icon src="res/icon/ios/icon-60@3x.png" width="180" height="180" />  
    <!-- iOS 7.0+ -->  
    <!-- iPhone / iPod Touch  -->  
    <icon src="res/icon/ios/icon-60.png" width="60" height="60" />  
    <icon src="res/icon/ios/icon-60@2x.png" width="120" height="120" />  
    <!-- iPad -->  
    <icon src="res/icon/ios/icon-76.png" width="76" height="76" />  
    <icon src="res/icon/ios/icon-76@2x.png" width="152" height="152" />  
    <!-- iOS 6.1 -->  
    <!-- Spotlight Icon -->  
    <icon src="res/icon/ios/icon-40.png" width="40" height="40" />  
    <icon src="res/icon/ios/icon-40@2x.png" width="80" height="80" />  
    <!-- iPhone / iPod Touch -->  
    <icon src="res/icon/ios/icon.png" width="57" height="57" />  
    <icon src="res/icon/ios/icon@2x.png" width="114" height="114" />  
    <!-- iPad -->  
    <icon src="res/icon/ios/icon-72.png" width="72" height="72" />  
    <icon src="res/icon/ios/icon-72@2x.png" width="144" height="144" />  
    <!-- iPhone Spotlight and Settings Icon -->  
    <icon src="res/icon/ios/icon-small.png" width="29" height="29" />  
    <icon src="res/icon/ios/icon-small@2x.png" width="58" height="58" />  
    <!-- iPad Spotlight and Settings Icon -->  
    <icon src="res/icon/ios/icon-50.png" width="50" height="50" />  
    <icon src="res/icon/ios/icon-50@2x.png" width="100" height="100" />  
    <!-- 如下是歡迎頁面,可根據須要進行添加 -->
    <splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/>  
    <splash src="res/screen/ios/Default@2x~iphone.png" width="640" height="960"/>  
    <splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/>  
    <splash src="res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>  
    <splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/>  
    <splash src="res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>  
    <splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>  
    <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>  
    <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>  
    <splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/>  
</platform>

其餘配置

  • 自動隱藏啓動頁面AutoHideSplashScreen(默認爲:true)git

    <preference name="AutoHideSplashScreen" value="true" />
  • 顯示啓動頁面的時間長度SplashScreenDelay(默認爲:3000)github

    <preference name="SplashScreenDelay" value="3000" />

    若想禁用啓動頁面,可設置爲:<preference name="SplashScreenDelay" value="0"/>apache

    若是是iOS平臺上想禁止啓動頁面,還須要添加<preference name="FadeSplashScreenDuration" value="0"/>app

  • 啓動頁面淡入淡出的效果iphone

    是否顯示淡入淡出效果FadeSplashScreen(默認爲:true)ide

    <preference name="FadeSplashScreen" value="false"/>

    淡入淡出效果的執行時間長度FadeSplashScreenDuration(默認爲:500)動畫

    <preference name="FadeSplashScreenDuration" value="750"/>

    注意:FadeSplashScreenDuration時間是包含在SplashScreenDelay的時間裏的。

  • 啓動頁面是否容許旋轉(默認爲:true)

    <preference name="ShowSplashScreenSpinner" value="false"/>
  • 插件還能夠經過js代碼調用,提供有如下兩個方法:

    navigator.splashscreen.hide();//隱藏啓動頁面
    
      navigator.splashscreen.show();//顯示啓動頁面
  • 在Android平臺下的特殊設置

    <preference name="SplashMaintainAspectRatio" value="true|false" />
      <preference name="SplashShowOnlyFirstTime" value="true|false" />

    SplashMaintainAspectRatio:選填項,默認爲false。當設置爲true時,則不會拉伸圖片來填充屏幕,會以圖片原始比例顯示圖片。

    SplashShowOnlyFirstTime:選填項,默認爲true。當設置爲false時,APP經過navigator.app.exitApp()代碼退出app後,在下次打開APP時,還會顯示啓動頁面。若爲true時,就不會出現。

2、圖標文件夾內容

根據上面的配置信息,你須要準備好你本身的app圖標和啓動畫面png文件:

存放路徑不是以www文件夾爲依據,而是以當前項目文件夾爲依據

projectRoot
    hooks
    platforms
    plugins
    www
        css
        img
        js
    res
        screen
            android
            ios
        icon
            android
            ios

應用程序圖標

可經過圖標工場一鍵生成多尺寸圖標。

  • 安卓圖標具體規格以下(存放目錄:res/icon/android/)

    36*36    drawable-ldpi/icon.png
      48*48    drawable-mdpi/icon.png
      72*72    drawable-hdpi/icon.png
      96*96    drawable-xhdpi/icon.png
      144*144  drawable-xxhdpi/icon.png
  • iOS圖標具體規格以下(存放目錄:res/icon/ios/)

    57*57   icon.png
      114*114 icon@2x.png
      29*29   icon-small.png
      58*58   icon-small@2x.png
      40*40   icon-40.png
      80*80   icon-40@2x.png
      50*50   icon-50.png
      100*100 icon-50@2x.png
      60*60   icon-60.png
      120*120 icon-60@2x.png
      180*180 icon-60@3x.png
      72*72   icon-72.png
      144*144 icon-72@2x.png
      76*76   icon-76.png
      152*152 icon-76@2x.png

應用程序啓動頁面

  • 安卓啓動畫面具體規格以下(存放目錄:res/screen/android/)

    960*720 splash-land-xhdpi.png
      640*480 splash-land-hdpi.png
      470*320 splash-land-mdpi.png
      426*320 splash-land-ldpi.png
      720*960 splash-port-xhdpi.png
      480*640 splash-port-hdpi.png
      320*470 splash-port-mdpi.png
      320*426 splash-port-ldpi.png
  • iOS啓動畫面具體規格以下(存放目錄:res/screen/ios/)

    320*480 Default~iphone.png
      640*960 Default@2x~iphone.png
      768*1024    Default-Portrait~ipad.png
      1536*2048   Default-Portrait@2x~ipad.png
      1024*768    Default-Landscape~ipad.png
      2048*1536   Default-Landscape@2x~ipad.png
      640*1136    Default-568h@2x~iphone.png
      750*1334    Default-667h.png
      1242*2208   Default-736h.png
      2208*1242   Default-Landscape-736h.png
相關文章
相關標籤/搜索