You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
13 KiB

8 years ago
  1. ---
  2. title: Splashscreen
  3. description: Control the splash screen for your app.
  4. ---
  5. <!--
  6. # license: Licensed to the Apache Software Foundation (ASF) under one
  7. # or more contributor license agreements. See the NOTICE file
  8. # distributed with this work for additional information
  9. # regarding copyright ownership. The ASF licenses this file
  10. # to you under the Apache License, Version 2.0 (the
  11. # "License"); you may not use this file except in compliance
  12. # with the License. You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing,
  17. # software distributed under the License is distributed on an
  18. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. # KIND, either express or implied. See the License for the
  20. # specific language governing permissions and limitations
  21. # under the License.
  22. -->
  23. |Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI |
  24. |:-:|:-:|:-:|:-:|:-:|:-:|
  25. |[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-splashscreen)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-splashscreen/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-splashscreen)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-splashscreen/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-splashscreen)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-splashscreen/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-splashscreen)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-splashscreen/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-splashscreen)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-splashscreen/)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-splashscreen.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-splashscreen)|
  26. # cordova-plugin-splashscreen
  27. This plugin is required to work with splash screens. This plugin displays and hides a splash screen during application launch.
  28. Report issues with this plugin on the [Apache Cordova issue tracker][Apache Cordova issue tracker].
  29. ## Installation
  30. // npm hosted (new) id
  31. cordova plugin add cordova-plugin-splashscreen
  32. // you may also install directly from this repo
  33. cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git
  34. ## Supported Platforms
  35. - Amazon Fire OS
  36. - Android
  37. - BlackBerry 10
  38. - iOS
  39. - Windows Phone 7 and 8
  40. - Windows (`cordova-windows` version >= 4.4.0 is required)
  41. - Browser
  42. __Note__: Extended splashscreen does not require the plugin on Windows (as opposed to Android and iOS) in case you don't use the plugin API, i.e. programmatic hide/show.
  43. ## Example Configuration
  44. In the top-level `config.xml` file (not the one in `platforms`), add configuration elements like those specified here.
  45. Please notice that the value of the "src" attribute is relative to the project root directory and not to the www directory (see `Directory structure` below). You can name the source image whatever you like. The internal name in the app is determined by Cordova.
  46. Directory structure:
  47. ```
  48. projectRoot
  49. hooks
  50. platforms
  51. plugins
  52. www
  53. css
  54. img
  55. js
  56. res
  57. screen
  58. android
  59. ios
  60. windows
  61. ```
  62. ```xml
  63. <platform name="android">
  64. <!-- you can use any density that exists in the Android project -->
  65. <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi"/>
  66. <splash src="res/screen/android/splash-land-ldpi.png" density="land-ldpi"/>
  67. <splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi"/>
  68. <splash src="res/screen/android/splash-land-xhdpi.png" density="land-xhdpi"/>
  69. <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi"/>
  70. <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi"/>
  71. <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi"/>
  72. <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi"/>
  73. </platform>
  74. <platform name="ios">
  75. <!-- images are determined by width and height. The following are supported -->
  76. <splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/>
  77. <splash src="res/screen/ios/Default@2x~iphone.png" width="640" height="960"/>
  78. <splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/>
  79. <splash src="res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
  80. <splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/>
  81. <splash src="res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
  82. <splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>
  83. <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>
  84. <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>
  85. <splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/>
  86. </platform>
  87. <platform name="windows">
  88. <!-- images are determined by width and height. The following are supported -->
  89. <splash src="res/screen/windows/splashscreen.png" width="620" height="300"/>
  90. <splash src="res/screen/windows/splashscreenphone.png" width="1152" height="1920"/>
  91. </platform>
  92. <platform name="blackberry10">
  93. <!-- Add a rim:splash element for each resolution and locale you wish -->
  94. <!-- http://developer.blackberry.com/html5/documentation/rim_splash_element.html -->
  95. <rim:splash src="res/screen/blackberry/splashscreen.png"/>
  96. </platform>
  97. <preference name="SplashScreenDelay" value="10000" />
  98. ```
  99. ## Preferences
  100. #### config.xml
  101. - `AutoHideSplashScreen` (boolean, default to `true`). Indicates whether to hide splash screen automatically or not. Splash screen hidden after amount of time specified in the `SplashScreenDelay` preference.
  102. ```xml
  103. <preference name="AutoHideSplashScreen" value="true" />
  104. ```
  105. - `SplashScreenDelay` (number, default to 3000). Amount of time in milliseconds to wait before automatically hide splash screen.
  106. ```xml
  107. <preference name="SplashScreenDelay" value="3000" />
  108. ```
  109. Note also that this value used to be seconds, and not milliseconds, so values less than 30 will still be treated as seconds. ( Consider this a deprecated patch that will disapear in some future version. )
  110. To disable the splashscreen add the following preference to `config.xml`:
  111. ```xml
  112. <preference name="SplashScreenDelay" value="0"/>
  113. ```
  114. **iOS Quirk**: to disable the splashscreen on `ios` platform you should also add `<preference name="FadeSplashScreenDuration" value="0"/>` to `config.xml`.
  115. - `FadeSplashScreen` (boolean, defaults to `true`): Set to `false` to
  116. prevent the splash screen from fading in and out when its display
  117. state changes.
  118. ```xml
  119. <preference name="FadeSplashScreen" value="false"/>
  120. ```
  121. - `FadeSplashScreenDuration` (float, defaults to `500`): Specifies the
  122. number of milliseconds for the splash screen fade effect to execute.
  123. ```xml
  124. <preference name="FadeSplashScreenDuration" value="750"/>
  125. ```
  126. _Note_: `FadeSplashScreenDuration` is included into `SplashScreenDelay`, for example if you have `<preference name="SplashScreenDelay" value="3000" />` and `<preference name="FadeSplashScreenDuration" value="1000"/>` defined in `config.xml`:
  127. - 00:00 - splashscreen is shown
  128. - 00:02 - fading has started
  129. - 00:03 - splashscreen is hidden
  130. Turning the fading off via `<preference name="FadeSplashScreen" value="false"/>` technically means fading duration to be `0` so that in this example the overall splash delay will still be 3 seconds.
  131. _Note_: This only applies to the app startup - you need to take the fading timeout into account when manually showing/hiding the splashscreen in the code:
  132. ```javascript
  133. navigator.splashscreen.show();
  134. window.setTimeout(function () {
  135. navigator.splashscreen.hide();
  136. }, splashDuration - fadeDuration);
  137. ```
  138. - `ShowSplashScreenSpinner` (boolean, defaults to `true`): Set to `false`
  139. to hide the splash-screen spinner.
  140. ```xml
  141. <preference name="ShowSplashScreenSpinner" value="false"/>
  142. ```
  143. ### Android Quirks
  144. In your `config.xml`, you can add the following preferences:
  145. ```xml
  146. <preference name="SplashMaintainAspectRatio" value="true|false" />
  147. <preference name="SplashShowOnlyFirstTime" value="true|false" />
  148. ```
  149. "SplashMaintainAspectRatio" preference is optional. If set to true, splash screen drawable is not stretched to fit screen, but instead simply "covers" the screen, like CSS "background-size:cover". This is very useful when splash screen images cannot be distorted in any way, for example when they contain scenery or text. This setting works best with images that have large margins (safe areas) that can be safely cropped on screens with different aspect ratios.
  150. The plugin reloads splash drawable whenever orientation changes, so you can specify different drawables for portrait and landscape orientations.
  151. "SplashShowOnlyFirstTime" preference is also optional and defaults to `true`. When set to `true` splash screen will only appear on application launch. However, if you plan to use `navigator.app.exitApp()` to close application and force splash screen appear on next launch, you should set this property to `false` (this also applies to closing the App with Back button).
  152. ### Browser Quirks
  153. You can use the following preferences in your `config.xml`:
  154. ```xml
  155. <platform name="browser">
  156. <preference name="SplashScreen" value="/images/browser/splashscreen.jpg" /> <!-- defaults to "/img/logo.png" -->
  157. <preference name="SplashScreenDelay" value="3000" /> <!-- defaults to "3000" -->
  158. <preference name="SplashScreenBackgroundColor" value="green" /> <!-- defaults to "#464646" -->
  159. <preference name="ShowSplashScreen" value="false" /> <!-- defaults to "true" -->
  160. <preference name="SplashScreenWidth" value="600" /> <!-- defaults to "170" -->
  161. <preference name="SplashScreenHeight" value="300" /> <!-- defaults to "200" -->
  162. </platform>
  163. ```
  164. __Note__: `SplashScreen` value should be absolute in order to work in a sub-page. The `SplashScreen` value is used only for the browser platform. The value will be ignored for other platforms.
  165. ### iOS Quirks
  166. - In iOS, the splashscreen images are called launch images. These images are mandatory on iOS.
  167. ### Windows Quirks
  168. - `SplashScreenSpinnerColor` (string, defaults to system accent color): hash, rgb notation or CSS color name.
  169. ```xml
  170. <preference name="SplashScreenSpinnerColor" value="#242424"/>
  171. <preference name="SplashScreenSpinnerColor" value="DarkRed"/>
  172. <preference name="SplashScreenSpinnerColor" value="rgb(50,128,128)"/>
  173. ```
  174. - `SplashScreenBackgroundColor` (string, defaults to #464646): hex notation.
  175. ```xml
  176. <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
  177. ```
  178. ## Methods
  179. - splashscreen.show
  180. - splashscreen.hide
  181. ## splashscreen.hide
  182. Dismiss the splash screen.
  183. ```js
  184. navigator.splashscreen.hide();
  185. ```
  186. ### BlackBerry 10, WP8, iOS Quirk
  187. The `config.xml` file's `AutoHideSplashScreen` setting must be
  188. `false`. To delay hiding the splash screen for two seconds, add a
  189. timer such as the following in the `deviceready` event handler:
  190. ```js
  191. setTimeout(function() {
  192. navigator.splashscreen.hide();
  193. }, 2000);
  194. ```
  195. ## splashscreen.show
  196. Displays the splash screen.
  197. ```js
  198. navigator.splashscreen.show();
  199. ```
  200. Your application cannot call `navigator.splashscreen.show()` until the app has
  201. started and the `deviceready` event has fired. But since typically the splash
  202. screen is meant to be visible before your app has started, that would seem to
  203. defeat the purpose of the splash screen. Providing some configuration in
  204. `config.xml` will automatically `show` the splash screen immediately after your
  205. app launch and before it has fully started and received the `deviceready`
  206. event. For this reason, it is unlikely you need to call `navigator.splashscreen.show()` to make the splash
  207. screen visible for app startup.
  208. [Apache Cordova issue tracker]: https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Splashscreen%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC