简体   繁体   中英

Phonegap Cordova - How to remove default splash screen?

When I used to start up my app, it would show the common splash screen: https://www.google.com/search?biw=1366&bih=667&tbm=isch&sa=1&q=cordova+android+splash+screen&oq=cordova+android+splash+screen&gs_l=img.3...3442.4414.0.4584.0.0.0.0.0.0.0.0..0.0....0...1c.1.64.img..0.0.0.HlLmVH4tGUs#imgrc=HJeAimnld9GDKM%3A

Now it seems it cuts off about 1/10th of the top of the image and covers the screen with it for the initial few seconds, THEN my app starts normally, like so:

开机画面

I have been ignoring it until I finished the app, now I am nearly done publishing and wish to fix this issue.

I was wondering if there is a way to take out the splash screen entirely. I tried removing the pictures from res/xml and adding

<preference name="SplashScreen" value="none"/>

but doesn't work.

This is for an android app.

I am going to make it for iOS soon after I finish and publish for android, so if they are different methods for different platforms, please include.

 //splashscreen.js var exec = require('cordova/exec'); var splashscreen = { show:function() { exec(null, null, "SplashScreen", "show", []); }, hide:function() { exec(null, null, "SplashScreen", "hide", []); } }; module.exports = splashscreen; 
 <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-splashscreen" version="2.1.0"> <name>Splashscreen</name> <description>Cordova Splashscreen Plugin</description> <license>Apache 2.0</license> <keywords>cordova,splashscreen</keywords> <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</repo> <issue>https://issues.apache.org/jira/browse/CB/component/12320653</issue> <engines> <engine name="cordova-android" version=">=3.6.0" /><!-- Requires CordovaPlugin.preferences --> </engines> <js-module src="www/splashscreen.js" name="SplashScreen"> <clobbers target="navigator.splashscreen" /> </js-module> <!-- android --> <platform name="android"> <config-file target="res/xml/config.xml" parent="/*"> <feature name="SplashScreen"> <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/> <param name="onload" value="true"/> </feature> </config-file> <source-file src="src/android/SplashScreen.java" target-dir="src/org/apache/cordova/splashscreen" /> </platform> <!-- amazon-fireos --> <platform name="amazon-fireos"> <config-file target="res/xml/config.xml" parent="/*"> <feature name="SplashScreen"> <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/> </feature> </config-file> <source-file src="src/android/SplashScreen.java" target-dir="src/org/apache/cordova/splashscreen" /> </platform> <!-- ubuntu --> <platform name="ubuntu"> <header-file src="src/ubuntu/splashscreen.h" /> <source-file src="src/ubuntu/splashscreen.cpp" /> </platform> <!-- ios --> <platform name="ios"> <config-file target="config.xml" parent="/*"> <feature name="SplashScreen"> <param name="ios-package" value="CDVSplashScreen"/> <param name="onload" value="true"/> </feature> </config-file> <header-file src="src/ios/CDVSplashScreen.h" /> <source-file src="src/ios/CDVSplashScreen.m" /> <header-file src="src/ios/CDVViewController+SplashScreen.h" /> <source-file src="src/ios/CDVViewController+SplashScreen.m" /> <framework src="CoreGraphics.framework" /> </platform> <!-- blackberry10 --> <platform name="blackberry10"> <source-file src="src/blackberry10/index.js" target-dir="SplashScreen" /> <config-file target="www/config.xml" parent="/widget"> <feature name="SplashScreen" value="SplashScreen"/> </config-file> </platform> <!-- wp8 --> <platform name="wp8"> <config-file target="config.xml" parent="/*"> <feature name="SplashScreen"> <param name="wp-package" value="SplashScreen"/> <param name="onload" value="true"/> </feature> </config-file> <source-file src="src/wp/SplashScreen.cs" /> <source-file src="src/wp/ResolutionHelper.cs" /> </platform> <!-- windows8 --> <platform name="windows8"> <js-module src="www/windows/SplashScreenProxy.js" name="SplashScreenProxy"> <merges target="" /> </js-module> </platform> <!-- windows --> <platform name="windows"> <js-module src="www/windows/SplashScreenProxy.js" name="SplashScreenProxy"> <merges target="" /> </js-module> </platform> <!-- tizen --> <platform name="tizen"> <js-module src="src/tizen/SplashScreenProxy.js" name="SplashScreenProxy"> <runs /> </js-module> </platform> <!-- browser --> <platform name="browser"> <js-module src="src/browser/SplashScreenProxy.js" name="SplashScreenProxy"> <runs /> </js-module> </platform> </plugin> //ReadMe # cordova-plugin-splashscreen [![Build Status](https://travis-ci.org/apache/cordova-plugin-splashscreen.svg)](https://travis-ci.org/apache/cordova-plugin-splashscreen) This plugin displays and hides a splash screen during application launch. ## Installation // npm hosted (new) id cordova plugin add cordova-plugin-splashscreen // you may also install directly from this repo cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git ## Supported Platforms - Amazon Fire OS - Android - BlackBerry 10 - iOS - Windows Phone 7 and 8 - Windows 8 - Windows - Browser ## Methods - splashscreen.show - splashscreen.hide ### Android Quirks In your `config.xml`, you need to add the following preferences: <preference name="SplashScreen" value="foo" /> <preference name="SplashScreenDelay" value="10000" /> <preference name="SplashMaintainAspectRatio" value="true|false" /> Where foo is the name of the splashscreen file, preferably a 9 patch file. Make sure to add your splashcreen files to your res/xml directory under the appropriate folders. The second parameter represents how long the splashscreen will appear in milliseconds. It defaults to 3000 ms. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html) for more information. "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. The plugin reloads splash drawable whenever orientation changes, so you can specify different drawables for portrait and landscape orientations. ### Browser Quirks You can use the following preferences in your `config.xml`: <platform name="browser"> <preference name="SplashScreen" value="images/browser/splashscreen.jpg" /> <!-- defaults to "img/logo.png" --> <preference name="SplashScreenDelay" value="10000" /> <!-- defaults to "3000" --> <preference name="SplashScreenBackgroundColor" value="green" /> <!-- defaults to "#464646" --> <preference name="ShowSplashScreen" value="false" /> <!-- defaults to "true" --> <preference name="SplashScreenWidth" value="600" /> <!-- defaults to "170" --> <preference name="SplashScreenHeight" value="300" /> <!-- defaults to "200" --> </platform> ### iOS Quirks - `FadeSplashScreen` (boolean, defaults to `true`): Set to `false` to prevent the splash screen from fading in and out when its display state changes. <preference name="FadeSplashScreen" value="false"/> - `FadeSplashScreenDuration` (float, defaults to `2`): Specifies the number of seconds for the splash screen fade effect to execute. <preference name="FadeSplashScreenDuration" value="4"/> - `ShowSplashScreenSpinner` (boolean, defaults to `true`): Set to `false` to hide the splash-screen spinner. <preference name="ShowSplashScreenSpinner" value="false"/> ## splashscreen.hide Dismiss the splash screen. navigator.splashscreen.hide(); ### BlackBerry 10, WP8, iOS Quirk The `config.xml` file's `AutoHideSplashScreen` setting must be `false`. To delay hiding the splash screen for two seconds, add a timer such as the following in the `deviceready` event handler: setTimeout(function() { navigator.splashscreen.hide(); }, 2000); ## splashscreen.show Displays the splash screen. navigator.splashscreen.show(); Your application cannot call `navigator.splashscreen.show()` until the app has started and the `deviceready` event has fired. But since typically the splash screen is meant to be visible before your app has started, that would seem to defeat the purpose of the splash screen. Providing some configuration in `config.xml` will automatically `show` the splash screen immediately after your app launch and before it has fully started and received the `deviceready` event. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html) for more information on doing this configuration. For this reason, it is unlikely you need to call `navigator.splashscreen.show()` to make the splash screen visible for app startup. 

 // to hide cordova.exec(null, null, "SplashScreen", "hide", []) // to show cordova.exec(null, null, "SplashScreen", "show", []) 

Or either replace default splash screen with your application specific screen or simply loader screen.

您可以使用可在不同平台(Android,iOS,Windows Phone,Amazon Fire等)上运行的SplashScreen插件( cordova-plugin-splashscreen ),然后在代码中要做的第一件事就是像这样隐藏启动画面:

navigator.splashscreen.hide();

It turns out I needed to edit (or remove) the index.css file in the css folder. Now it works like a charm :)

Try 'cordova plugin remove splashscreen'

I am developing a phonegap application (for browser and android) and it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM