代码之家  ›  专栏  ›  技术社区  ›  tery.blargh

Phonegap Cordova-如何删除默认启动屏幕?

  •  2
  • tery.blargh  · 技术社区  · 9 年前

    当我过去启动我的应用程序时,它会显示常见的启动屏幕: 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

    现在,它似乎切断了图像顶部的1/10,并在最初的几秒钟内覆盖屏幕,然后我的应用程序正常启动,如下所示:

    Splash Screen

    我一直忽略它,直到我完成了应用程序,现在我几乎完成了发布,希望解决这个问题。

    我想知道是否有一种方法可以完全去掉初始屏幕。我尝试从res/xml中删除图片并添加

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

    但不起作用。

    这是一个android应用程序。

    我将在我完成并发布android后很快为iOS制作,所以如果它们是不同平台的不同方法,请包括在内。

    4 回复  |  直到 9 年前
        1
  •  2
  •   Alvaro Montoro    9 年前

    你可以使用SplashScreen插件( cordova-plugin-splashscreen )在不同平台(Android、iOS、Windows Phone、Amazon Fire等)上运行,那么在代码中首先要做的就是像这样隐藏屏幕:

    navigator.splashscreen.hide();
    
        2
  •  2
  •   Rahul Huljute    9 年前

    //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.
    
        3
  •  1
  •   Hugo    7 年前

    尝试“cordova plugin remove splashscreen”

    我正在开发一个phonegap应用程序(用于浏览器和android),它对我有效。

        4
  •  0
  •   tery.blargh    8 年前

    事实证明,我需要编辑(或删除)索引。css文件夹中的css文件。现在它就像一种魅力:)