Apache Cordova启动画面未在Android中显示

时间:2014-10-17 14:13:16

标签: android cordova splash-screen

我正在运行Apache Cordova 3.6.3-0.2.13。我试着让启动画面工作。我已按照http://cordova.apache.org/docs/en/3.6.0/config_ref_images.md.html#Icons%20and%20Splash%20Screens上的文档进行操作。图标正在运行,但启动画面没有成功。我们还在Cordova之上使用Ionic框架(版本1.2.8)。

我做了什么:

从项目根目录为config.xml添加了图标和启动画面:

<preference name="SplashScreen" value="splash"/>
<preference name="SplashScreenDelay" value="10000"/>
<platform name="android">
  <icon src="icons/icon.png"/>

  <!-- you can use any density that exists in the Android project -->
  <splash src="icons/android-splash-land-hdpi.png" density="land-hdpi"/>
  <splash src="icons/android-splash-land-ldpi.png" density="land-ldpi"/>
  <splash src="icons/android-splash-land-mdpi.png" density="land-mdpi"/>
  <splash src="icons/android-splash-land-xhdpi.png" density="land-xhdpi"/>

  <splash src="icons/android-splash-port-hdpi.png" density="port-hdpi"/>
  <splash src="icons/android-splash-port-ldpi.png" density="port-ldpi"/>
  <splash src="icons/android-splash-port-mdpi.png" density="port-mdpi"/>
  <splash src="icons/android-splash-port-xhdpi.png" density="port-xhdpi"/>
</platform>

当然,icons目录存在,文件也就位。当我使用ionic run androidcordova run android构建项目时。构建过程还会在platforms/android/res/drawable目录中创建图标和启动画面!

位于platforms/android/res/xml/config.xml的配置文件也已正确更新,并且<preference><icon>以及<splash>元素已到位。

我也尝试使用org.apache.cordova.splashscreen插件,也没有成功。我已使用ionic plugin add org.apache.cordova.splashscreen添加了该插件,并添加了onDeviceReady代码navigator.splashscreen.show();。但这也没有表现出来。

我在这里缺少什么?

9 个答案:

答案 0 :(得分:52)

我自己就是这个问题。改变这个

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

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

这解决了它。

源: http://forum.ionicframework.com/t/need-help-with-displaying-splash-screen-on-android-cordova-3-6/10436/12

答案 1 :(得分:14)

我必须安装启动画面插件才能使其正常工作

cordova plugin add cordova-plugin-splashscreen

以及添加

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

<preference name="SplashScreenDelay" value="2000" />

答案 2 :(得分:10)

对于新来者和那些仍然面临这个问题的人

1)在 config.xml

中添加启动画面首选项
<preference
    name="SplashScreen"
    value="screen" />
<preference
    name="AutoHideSplashScreen"
    value="true" />
<preference
    name="SplashScreenDelay"
    value="5000" />

<feature name="SplashScreen" >
    <param
        name="android-package"
        value="org.apache.cordova.splashscreen.SplashScreen" />

    <param
        name="onload"
        value="true" />
</feature>

2)在 config.xml

中声明启动画面

    <!-- you can use any density that exists in the Android project -->
    <splash
        density="land-hdpi"
        src="res/drawable-land-hdpi/splash.png" />
    <splash
        density="land-ldpi"
        src="res/drawable-land-ldpi/splash.png" />
    <splash
        density="land-mdpi"
        src="res/drawable-land-mdpi/splash.png" />
    <splash
        density="land-xhdpi"
        src="res/drawable-land-xhdpi/splash.png" />
    <splash
        density="port-hdpi"
        src="res/drawable-hdpi/splash.png" />
    <splash
        density="port-ldpi"
        src="res/drawable-ldpi/splash.png" />
    <splash
        density="port-mdpi"
        src="res/drawable-mdpi/splash.png" />
    <splash
        density="port-xhdpi"
        src="res/drawable-xhdpi/splash.png" />
</platform>

3)最后将this class添加到 org.apache.cordova.splashscreen

下的android项目结构中

将其安装为Cordova插件。

答案 3 :(得分:2)

我在android上有类似的问题,我将Splash Screen直接放入res/drawable-hdpi并在cordova构建期间遇到以下错误。

res/drawable-hdpi-v4/DocBackground.png: Invalid file name: must contain only [a-z0-9_.]

当我对文件名进行去大写时,在~project/icons中,cordova构建将它们复制到res/drawable文件夹&amp;启动画面工作。

答案 4 :(得分:1)

在仔细关注PhoneGap CLI启动画面说明后,我的Android启动画面仍未显示。然后我查看了platforms / android下的build.gradle,注意到我对defaultConfig块所做的更改导致AndroidManifest.xml的更改最终阻止了启动画面的工作。下面是我使用的defaultConfig块:

defaultConfig {
    applicationId "com.leadingedje"
    minSdkVersion 17
    targetSdkVersion 21
    versionCode getAppVersionCode()
    versionName getAppVersionName()
}

当我从build.gradle中删除此块时,启动画面重新开始工作。

答案 5 :(得分:1)

Splashscreen集成:

的Android

  1. 将Splashscreen图像添加到以下文件夹中:

    root/res/drawable-land-hdpi/screen.png
    root/res/drawable-land-ldpi/screen.png
    root/res/drawable-land-mdpi/screen.png
    root/res/drawable-land-xdpi/screen.png
    
    root/res/drawable-port-hdpi/screen.png
    root/res/drawable-port-ldpi/screen.png
    root/res/drawable-port-mdpi/screen.png
    root/res/drawable-port-xdpi/screen.png
    
  2. 将启动画面插件添加到android项目中。 (git:git://git.apache.org/cordova-plugin-splashscreen.git)

    src/org/apache/cordova/splashscreen/SplashScreen.java
    
  3. 在assets / www / js / lib / android / plugins / cordova-plugin-splashscreen / www /中添加插件javascript文件 (git:https://github.com/apache/cordova-plugin-splashscreen/blob/master/www/splashscreen.js

  4. 在cordova_plugins.js中添加插件entery

    {
        "file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
        "id": "cordova-plugin-splashscreen.SplashScreen",
        "clobbers": [
            "navigator.splashscreen"
        ]
    },
    
    
    "cordova-plugin-splashscreen": "3.1.0",..   
    
  5. 在config.xml中添加以下代码

    <preference name="SplashScreen"         value="screen"/>
    <preference name="SplashScreenDelay"    value="5000" />
    <feature name="SplashScreen">
        <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
        <param name="onload" value="true" />
    </feature>
    
  6. 现在构建android项目。

答案 6 :(得分:0)

我通过添加默认的splash标记

解决了这个问题

将其添加到根目标中的config.xml或www / config.xml

<gap:splash src="splash.png" />

答案 7 :(得分:0)

我遇到了同样的问题,我使用以下配置修复了它: -

安装启动画面插件

cordova plugin add cordova-plugin-splashscreen

接下来,我们需要在config.xml中添加以下首选项,

<preference name="SplashScreenDelay" value="3000" />
<preference name="SplashMaintainAspectRatio" value="true" />

将Splashscreen图像添加到下面的文件夹

<platform name="android">
    <splash qualifier="land-hdpi" src="res/screen/android/splash-land-hdpi.png" />
    <splash qualifier="land-ldpi" src="res/screen/android/splash-land-ldpi.png" />
    <splash qualifier="land-mdpi" src="res/screen/android/splash-land-mdpi.png" />
    <splash qualifier="land-xhdpi" src="res/screen/android/splash-land-xhdpi.png" />
    <splash qualifier="land-xxhdpi" src="res/screen/android/splash-land-xxhdpi.png" />
    <splash qualifier="land-xxxhdpi" src="res/screen/android/splash-land-xxxhdpi.png" />
    <splash qualifier="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
    <splash qualifier="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
    <splash qualifier="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
    <splash qualifier="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
    <splash qualifier="port-xxhdpi" src="res/screen/android/splash-port-xxhdpi.png" />
    <splash qualifier="port-xxxhdpi" src="res/screen/android/splash-port-xxxhdpi.png" />
</platform>

land-ldpi不是密度而是限定符

因此,正确的每个启动标记如下:

<splash qualifier="land-ldpi" src="res/screen/android/splash-land-ldpi.png" />

完成上述配置后,下面的步骤非常重要,

<platform name="android">
   <preference name="SplashScreen" value="screen" />
</platform>

答案 8 :(得分:0)

2019年2月底:

我只做了两件事,就奏效了:

  • 安装插件:

    cordova plugin add cordova-plugin-splashscreen

  • 在config.xml中添加以下内容,并具有相应的图像

(如果需要,第一条初始线是通用的屏幕尺寸)

<platform name="android">
    <splash src="res/screen/android/splash-2732x2732.png" />

    <splash density="land-ldpi" src="res/screen/android/splash-land-320x200-ldpi.png" />
    <splash density="land-mdpi" src="res/screen/android/splash-land-480x320-mdpi.png" />
    <splash density="land-hdpi" src="res/screen/android/splash-land-800x480-hdpi.png" />
    <splash density="land-xhdpi" src="res/screen/android/splash-land-1280x720-xhdpi.png" />
    <splash density="land-xxhdpi" src="res/screen/android/splash-land-1600x960-xxhdpi.png" />
    <splash density="land-xxxhdpi" src="res/screen/android/splash-land-1920x1280-xxxhdpi.png" />
    <splash density="port-ldpi" src="res/screen/android/splash-port-200x320-ldpi.png" />
    <splash density="port-mdpi" src="res/screen/android/splash-port-320x480-mdpi.png" />
    <splash density="port-hdpi" src="res/screen/android/splash-port-480x800-hdpi.png" />
    <splash density="port-xhdpi" src="res/screen/android/splash-port-720x1280-xhdpi.png" />
    <splash density="port-xxhdpi" src="res/screen/android/splash-port-960x1600-xxhdpi.png" />
    <splash density="port-xxxhdpi" src="res/screen/android/splash-port-1280x1920-xxxhdpi.png" />
</platform>