UNPKG

13.1 kBMarkdownView Raw
1---
2title: Splashscreen
3description: 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
24|Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI |
25|:-:|:-:|:-:|:-:|:-:|:-:|
26|[![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)|
27
28# cordova-plugin-splashscreen
29
30This plugin is required to work with splash screens. This plugin displays and hides a splash screen during application launch.
31
32Report issues with this plugin on the [Apache Cordova issue tracker][Apache Cordova issue tracker].
33
34## Installation
35
36 // npm hosted (new) id
37 cordova plugin add cordova-plugin-splashscreen
38
39 // you may also install directly from this repo
40 cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git
41
42## Supported Platforms
43
44- Amazon Fire OS
45- Android
46- BlackBerry 10
47- iOS
48- Windows Phone 7 and 8
49- Windows (`cordova-windows` version >= 4.4.0 is required)
50- Browser
51
52__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.
53
54## Example Configuration
55In the top-level `config.xml` file (not the one in `platforms`), add configuration elements like those specified here.
56
57Please 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.
58
59Directory structure:
60
61```
62projectRoot
63 hooks
64 platforms
65 plugins
66 www
67 css
68 img
69 js
70 res
71 screen
72 android
73 ios
74 windows
75```
76
77```xml
78<platform name="android">
79 <!-- you can use any density that exists in the Android project -->
80 <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi"/>
81 <splash src="res/screen/android/splash-land-ldpi.png" density="land-ldpi"/>
82 <splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi"/>
83 <splash src="res/screen/android/splash-land-xhdpi.png" density="land-xhdpi"/>
84
85 <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi"/>
86 <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi"/>
87 <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi"/>
88 <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi"/>
89</platform>
90
91<platform name="ios">
92 <!-- images are determined by width and height. The following are supported -->
93 <splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/>
94 <splash src="res/screen/ios/Default@2x~iphone.png" width="640" height="960"/>
95 <splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/>
96 <splash src="res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
97 <splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/>
98 <splash src="res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
99 <splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>
100 <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>
101 <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>
102 <splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/>
103</platform>
104
105<platform name="windows">
106 <!-- images are determined by width and height. The following are supported -->
107 <splash src="res/screen/windows/splashscreen.png" width="620" height="300"/>
108 <splash src="res/screen/windows/splashscreenphone.png" width="1152" height="1920"/>
109</platform>
110
111<platform name="blackberry10">
112 <!-- Add a rim:splash element for each resolution and locale you wish -->
113 <!-- http://developer.blackberry.com/html5/documentation/rim_splash_element.html -->
114 <rim:splash src="res/screen/blackberry/splashscreen.png"/>
115</platform>
116
117<preference name="SplashScreenDelay" value="10000" />
118```
119
120## Preferences
121
122#### config.xml
123
124- `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.
125
126```xml
127 <preference name="AutoHideSplashScreen" value="true" />
128```
129
130- `SplashScreenDelay` (number, default to 3000). Amount of time in milliseconds to wait before automatically hide splash screen.
131
132```xml
133 <preference name="SplashScreenDelay" value="3000" />
134```
135
136Note 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. )
137
138To disable the splashscreen add the following preference to `config.xml`:
139```xml
140<preference name="SplashScreenDelay" value="0"/>
141```
142
143**iOS Quirk**: to disable the splashscreen on `ios` platform you should also add `<preference name="FadeSplashScreenDuration" value="0"/>` to `config.xml`.
144
145- `FadeSplashScreen` (boolean, defaults to `true`): Set to `false` to
146 prevent the splash screen from fading in and out when its display
147 state changes.
148
149```xml
150 <preference name="FadeSplashScreen" value="false"/>
151```
152
153- `FadeSplashScreenDuration` (float, defaults to `500`): Specifies the
154 number of milliseconds for the splash screen fade effect to execute.
155
156```xml
157 <preference name="FadeSplashScreenDuration" value="750"/>
158```
159
160_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`:
161
162- 00:00 - splashscreen is shown
163- 00:02 - fading has started
164- 00:03 - splashscreen is hidden
165
166Turning 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.
167
168_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:
169
170```javascript
171navigator.splashscreen.show();
172window.setTimeout(function () {
173 navigator.splashscreen.hide();
174}, splashDuration - fadeDuration);
175```
176
177- `ShowSplashScreenSpinner` (boolean, defaults to `true`): Set to `false`
178 to hide the splash-screen spinner.
179
180```xml
181 <preference name="ShowSplashScreenSpinner" value="false"/>
182```
183
184### Android Quirks
185
186In your `config.xml`, you can add the following preferences:
187
188```xml
189<preference name="SplashMaintainAspectRatio" value="true|false" />
190<preference name="SplashShowOnlyFirstTime" value="true|false" />
191```
192
193"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.
194
195The plugin reloads splash drawable whenever orientation changes, so you can specify different drawables for portrait and landscape orientations.
196
197"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).
198
199### Browser Quirks
200
201You can use the following preferences in your `config.xml`:
202
203```xml
204<platform name="browser">
205 <preference name="SplashScreen" value="/images/browser/splashscreen.jpg" /> <!-- defaults to "/img/logo.png" -->
206 <preference name="SplashScreenDelay" value="3000" /> <!-- defaults to "3000" -->
207 <preference name="SplashScreenBackgroundColor" value="green" /> <!-- defaults to "#464646" -->
208 <preference name="ShowSplashScreen" value="false" /> <!-- defaults to "true" -->
209 <preference name="SplashScreenWidth" value="600" /> <!-- defaults to "170" -->
210 <preference name="SplashScreenHeight" value="300" /> <!-- defaults to "200" -->
211</platform>
212```
213
214__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.
215
216### iOS Quirks
217
218- In iOS, the splashscreen images are called launch images. These images are mandatory on iOS.
219
220### Windows Quirks
221
222- `SplashScreenSpinnerColor` (string, defaults to system accent color): hash, rgb notation or CSS color name.
223
224```xml
225<preference name="SplashScreenSpinnerColor" value="#242424"/>
226<preference name="SplashScreenSpinnerColor" value="DarkRed"/>
227<preference name="SplashScreenSpinnerColor" value="rgb(50,128,128)"/>
228```
229
230- `SplashScreenBackgroundColor` (string, defaults to #464646): hex notation.
231
232```xml
233<preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
234```
235
236## Methods
237
238- splashscreen.show
239- splashscreen.hide
240
241## splashscreen.hide
242
243Dismiss the splash screen.
244
245```js
246navigator.splashscreen.hide();
247```
248
249
250### BlackBerry 10, WP8, iOS Quirk
251
252The `config.xml` file's `AutoHideSplashScreen` setting must be
253`false`. To delay hiding the splash screen for two seconds, add a
254timer such as the following in the `deviceready` event handler:
255
256```js
257setTimeout(function() {
258 navigator.splashscreen.hide();
259}, 2000);
260```
261
262## splashscreen.show
263
264Displays the splash screen.
265
266```js
267navigator.splashscreen.show();
268```
269
270Your application cannot call `navigator.splashscreen.show()` until the app has
271started and the `deviceready` event has fired. But since typically the splash
272screen is meant to be visible before your app has started, that would seem to
273defeat the purpose of the splash screen. Providing some configuration in
274`config.xml` will automatically `show` the splash screen immediately after your
275app launch and before it has fully started and received the `deviceready`
276event. For this reason, it is unlikely you need to call `navigator.splashscreen.show()` to make the splash
277screen visible for app startup.
278
279[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