2016-02-26 2 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/10th в верхней части изображения и покрывает экран с ним для первых нескольких секунд, а затем мое приложение начинает работать нормально, так как:

Splash Screen

Я игнорировал его, пока я не закончил приложение, теперь я почти закончил публикацию и хочу, чтобы исправить эту проблему.

Мне было интересно, есть ли способ полностью вынести заставку. Я попытался удалить фотографии из res/xml и добавить

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

но не работает.

Это приложение для Android.

Я собираюсь сделать это для iOS вскоре после того, как закончу и опубликую для android, поэтому, если они разные методы для разных платформ, пожалуйста, включите.

+1

Какое приложение оно? (просто любопытно). –

+0

Простое приложение для игры –

+1

Что он будет называться? (если вы это поняли) –

ответ

0

Оказалось, мне нужно было отредактировать (или удалить) файл index.css в папке 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

Вы можете использовать плагин SplashScreen (cordova-plugin-splashscreen), который работает на различных платформах (Android, IOS, Windows Phone, Amazon Огонь, и т. д.), то первое, что нужно сделать в вашем коде, - это скрыть всплывающее окно следующим образом:

navigator.splashscreen.hide(); 
+0

Я добавил плагин, то же самое, не повезло –

0

Try «Cordova плагин удалить SplashScreen»

Я занимаюсь разработкой приложений PhoneGap (для браузера и Android) и он работал на меня.

Смежные вопросы