2016-02-26 46 views
2

當我用來啓動我的應用程序,它會顯示常見的閃屏: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%3APhonegap Cordova - 如何刪除默認啓動畫面?

現在看來,它切斷了圖像的頂部約1/10,並用它覆蓋在屏幕最初幾秒鐘,然後我的應用程序啓動正常,像這樣:

Splash Screen

我一直忽略了它,直到我完成了應用程序,現在我幾乎做了發佈,並希望解決這個問題。

我想知道是否有辦法完全取出啓動畫面。我試圖從res/xml中刪除圖片並添加

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

但是不起作用。

這是一個android應用程序。

我將在完成併發布android之後儘快爲iOS創建它,因此如果它們是針對不同平臺的不同方法,請包括。

+1

它是什麼應用程序? (只是好奇)。 –

+0

一個簡單的遊戲應用程序 –

+1

它將被稱爲什麼? (如果你已經知道了) –

回答

0

原來我需要編輯(或刪除)css文件夾中的index.css文件。現在,它就像一個魅力:)

2

//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="/*"> 
 
\t \t  <feature name="SplashScreen"> 
 
\t \t \t  <param name="ios-package" value="CDVSplashScreen"/> 
 
\t \t \t  <param name="onload" value="true"/> 
 
\t \t  </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" /> 
 

 
\t  <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. 
+0

我讀過並試過這個 –

+0

有沒有一個特定的地方把這個? –

+0

參考上面更新的答案。 –

2

您可以使用閃屏插件(cordova-plugin-splashscreen)在不同平臺上工作(Android,iOS設備的Windows Phone,亞馬遜火,等等),那麼你的代碼中的第一件事就是像這樣隱藏啓動畫面:

navigator.splashscreen.hide(); 
+0

我添加了插件,同樣的事情,沒有運氣 –

0

嘗試「科爾多瓦插件刪除閃屏」

我開發一個PhoneGap的應用程序(瀏覽器和Android),它爲我工作。