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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26426981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:23:11  来源:igfitidea点击:

Apache Cordova splash screens not showing in Android

androidcordovasplash-screen

提问by Mark Veenstra

I am running Apache Cordova 3.6.3-0.2.13. And I try to get the splash screens working. I have followed the documentation on http://cordova.apache.org/docs/en/3.6.0/config_ref_images.md.html#Icons%20and%20Splash%20Screens. And the icons are working, but no success for the splash screens. We are also using the Ionic framework (version 1.2.8) on top of Cordova.

我正在运行 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)。

What I have done:

我做了什么:

Added icons and splash screens to config.xml from the project root:

从项目根目录向 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>

Ofcourse the iconsdirectory exists and also the files are in place. When I build the project with ionic run androidor cordova run android. The build process also creates the icons and splash screens into the platforms/android/res/drawabledirectory!

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

Also the config file located at platforms/android/res/xml/config.xmlis correctly updated and the <preference>and <icon>and <splash>elements are in place.

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

I also tried with the org.apache.cordova.splashscreenplugin and also no success. I have added the plugin with ionic plugin add org.apache.cordova.splashscreenand also added onDeviceReadythe code navigator.splashscreen.show();. But this also shows nothing.

我也试过org.apache.cordova.splashscreen插件,也没有成功。我已经添加了插件ionic plugin add org.apache.cordova.splashscreen并添加onDeviceReady了代码navigator.splashscreen.show();。但这也说明不了什么。

What am I missing here?

我在这里缺少什么?

回答by Filipe Silva

Just had this problem myself. Change this

自己刚遇到这个问题。改变这个

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

to

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

This fixed it.

这修复了它。

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

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

回答by kentrh

I had to install the splash screen plugin to make it work

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

cordova plugin add cordova-plugin-splashscreen

cordova plugin add cordova-plugin-splashscreen

as well as adding

以及添加

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

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

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

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

回答by Hitesh Sahu

For new comers and those who are still facing this issue

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

1) Add Splash screen preference in config.xml

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) Declare your splash screens in config.xml

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) Finally Add this classinto your android project structure under org.apache.cordova.splashscreenpackage

3)最后将这个类添加到你的android项目结构中org.apache.cordova.splashscreen包下

or

或者

install it as Cordova plugin.

将其安装为 Cordova 插件。

回答by user3094755

I had a similar issue on android, I put the Splash Screen Directly into res/drawable-hdpiand got the following error during cordova build.

我在android上遇到了类似的问题,我将启动画面直接放入res/drawable-hdpi并在cordova构建期间出现以下错误。

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

When I de-capitalised the file name, in ~project/icons, cordova build copied them to the res/drawablefolder & splash screen worked.

当我取消大写文件名时,在~project/icons,cordova build 将它们复制到res/drawable文件夹并且启动画面工作。

回答by jkwuc89

After carefully following the PhoneGap CLI splash screen instructions, my Android splash screen was still not showing up. I then looked at build.gradle under platforms/android and noticed that changes I made to the defaultConfig block were causing changes to AndroidManifest.xml that ultimately prevented the splash screen from working. Below is the defaultConfig block I was using:

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

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

When I removed this block from build.gradle, the splash screen started working again.

当我从 build.gradle 中删除这个块时,启动画面又开始工作了。

回答by Atif Hussain

Splashscreen integration:

闪屏集成:

Android

安卓

  1. Add the Splashscreen images to folders like below:

    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. Add splash Screen plugin to android project. (git : git://git.apache.org/cordova-plugin-splashscreen.git)

    src/org/apache/cordova/splashscreen/SplashScreen.java
    
  3. Add plugin javascript file in assets/www/js/lib/android/plugins/cordova-plugin-splashscreen/www/ (git : https://github.com/apache/cordova-plugin-splashscreen/blob/master/www/splashscreen.js)

  4. Add plugin entery in cordova_plugins.js

    {
        "file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
        "id": "cordova-plugin-splashscreen.SplashScreen",
        "clobbers": [
            "navigator.splashscreen"
        ]
    },
    
    
    "cordova-plugin-splashscreen": "3.1.0",..   
    
  5. Add following code in 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. now build the android project.

  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/启动画面.js)

  4. 在cordova_plugins.js 中添加插件输入

    {
        "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项目。

回答by Nimesh khatri

I'd faced same issue and I've fixed it by using following configuration :-

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

install splash screen plugin

安装启动画面插件

cordova plugin add cordova-plugin-splashscreen

Next we need to add following preference in config.xml,

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

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

Add the Splashscreen images to folders like below

将 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 is not a density but a qualifier

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

Therefore the correct each splash tag as below:

因此,正确的每个飞溅标签如下:

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

After above configuration, below step is very important,

以上配置完成后,下面的步骤很重要,

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

回答by Manohar Reddy Poreddy

2019 February end:

2019年2月结束:

Only two things I did and it worked:

我只做了两件事并且它奏效了:

  • Install plugin:

    cordova plugin add cordova-plugin-splashscreen

  • Add below to config.xml, have corresponding images

  • 安装插件:

    cordova plugin add cordova-plugin-splashscreen

  • 将下面添加到config.xml,有对应的图片

(1st splash line is a generic screen size, if you want)

(如果需要,第一条启动线是通用屏幕尺寸)

<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>

回答by Dev

I solved the problem by adding default splash tag

我通过添加默认的飞溅标签解决了这个问题

Add this to config.xml in the root destination or in www/config.xml

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

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