本文介绍了科尔多瓦闪屏没有显示在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是全新的科尔多瓦和想获得初始屏幕在Android上工作。我跟着一些教程的文字和对SO这里评论的问题,但它不工作呢。

我使用'科尔多瓦CLI的方法 - 这是我的/config.xml:

 < XML版本='1.0'编码='UTF-8'&GT?;
<控件ID =输入com.example.hello版本=0.0.1的xmlns =htt​​p://www.w3.org/ns/widgets的xmlns:CDV =htt​​p://cordova.apache.org /ns/1.0\">
    <名称>&的HelloWorld LT; /名称>    < preference NAME =闪屏VALUE =画面/>
    < preference NAME =SplashScreenDelay值=2000/>    <描述>
        样本的Apache科尔多瓦应用程序响应deviceready事件。
    < /描述>
    <作者的电子邮件[email protected]的href =htt​​p://cordova.io>
        Apache的科尔多瓦队
    < /笔者>
    <内容SRC =的index.html/>
    <插件名称=科尔多瓦 - 插件白名单规范=1/>
    <获得原产=*/>
    <允许意图HREF =HTTP:// * / */>
    <允许意图HREF =htt​​ps://开头* / */>
    <允许意图HREF =电话:*/>
    <允许意图HREF =短信:*/>
    <允许意图HREF =电子邮件地址:*/>
    <允许意图HREF =缘:*/>
    <平台名称=机器人>        <允许意图HREF =行情:*/>        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=土地华电国际/>
        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=土地LDPI/>
        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=土地MDPI/>
        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=土地xhdpi/>        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=港华电国际/>
        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=港LDPI/>
        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=港MDPI/>
        <飞溅SRC =RES /屏幕/安卓/飞溅logo.png密度=港xhdpi/>        <图标密度=LDPISRC =RES /屏幕/安卓/的icon.png/>
        <图标密度=MDPISRC =RES /屏幕/安卓/的icon.png/>
        <图标密度=华电国际SRC =RES /屏幕/安卓/的icon.png/>
        <图标密度=xhdpiSRC =RES /屏幕/安卓/的icon.png/>
    < /平台>    <平台名称=IOS>
        <允许意图HREF =ITMS:*/>
        <允许意图HREF =ITMS-应用:*/>
    < /平台>
< /部件>

我知道我应该有不同的图像大小为每个密度,但是这是一个测试项目,所以请忽略这一点。

我已经添加了科尔多瓦 - 插件,闪屏到我的项目。

 科尔多瓦插件添加科尔多瓦 - 插件,启动画面

仍然没有显示启动画面 - 而不是blackscreen轮番上涨时,应用程序在模拟器上运行。几秒钟后,blackscreen消失并出现默认的设备就绪科尔多瓦屏幕。

我所做的一切,在其他地方提出 - 你们可以发现什么是错的。

FYI我一直在寻找在/ plataforms目录,它似乎设置是否正确。

下面的片段来自/platforms/android/res/xml/config.xml:

 <飞溅密度=土地华电国际SRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=土地LDPISRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=土地MDPISRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=土地xhdpiSRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=港华电国际SRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=港LDPISRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=港MDPISRC =RES /绘-土地xhdpi / screen.png/>
<飞溅密度=港xhdpiSRC =RES /绘-土地xhdpi / screen.png/>
<图标密度=LDPISRC =RES /屏幕/安卓/的icon.png/>
<图标密度=MDPISRC =RES /屏幕/安卓/的icon.png/>
<图标密度=华电国际SRC =RES /屏幕/安卓/的icon.png/>
<图标密度=xhdpiSRC =RES /屏幕/安卓/的icon.png/>

有上面列出的每个目录下的文件screen.png - 如此看来科尔多瓦正确地做其工作。


主要活动:

 包输入com.example.hello;进口android.os.Bundle;
导入org.apache.cordova *。公共类MainActivity扩展CordovaActivity
{
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //设置以<内容SRC =的index.html/>在config.xml中
        使用loadURL(launchUrl);
    }
}


解决方案

我这个问题相当长的一段时间挣扎过,并发现问题是在值 SplashScreenDelay FadeSplashScreenDuration

如果你看一下 SplashScreen.java ,你会发现,在 showSplashScreen 函数执行以下内容:

 最终诠释fadeSplashScreenDuration = getFadeDuration();
最终诠释effectiveSplashDuration = Math.max(0,splashscreenTime - fadeSplashScreenDuration);

在你的配置,你设置了 SplashScreenDelay 是2000毫秒。

getFadeDuration 查找 FadeSplashScreenDuration 元素,并在未找到(在这种情况下)回落到默认 DEFAULT_SPLASHSCREEN_DURATION ,这是3000毫秒,从而为 effectiveSplashDuration 负值。显然,这将导致显示无闪屏。

因此​​,解决方案是


  • FadeSplashScreenDuration 元素添加到设置为0的值配置(或任意数量的的超过2000个)

  • 增加 SplashScreenDelay 的4000的值(或任意数量的放大的大于3000)

I'm brand new to Cordova and am trying to get the splash screen working on Android. I've followed a few tutorials to the letter and have reviewed the questions here on SO but it's not working yet.

I'm using the 'Cordova CLI' approach - here is my /config.xml:

   <?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloWorld</name>

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

    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="[email protected]" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">

        <allow-intent href="market:*" />

        <splash src="res/screen/android/splash-logo.png" density="land-hdpi"/>
        <splash src="res/screen/android/splash-logo.png" density="land-ldpi"/>
        <splash src="res/screen/android/splash-logo.png" density="land-mdpi"/>
        <splash src="res/screen/android/splash-logo.png" density="land-xhdpi"/>

        <splash src="res/screen/android/splash-logo.png" density="port-hdpi"/>
        <splash src="res/screen/android/splash-logo.png" density="port-ldpi"/>
        <splash src="res/screen/android/splash-logo.png" density="port-mdpi"/>
        <splash src="res/screen/android/splash-logo.png" density="port-xhdpi"/>

        <icon density="ldpi" src="res/screen/android/icon.png" />
        <icon density="mdpi" src="res/screen/android/icon.png" />
        <icon density="hdpi" src="res/screen/android/icon.png" />
        <icon density="xhdpi" src="res/screen/android/icon.png" />
    </platform>

    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

I know I should have different image sizes for each density but this is a test project so please ignore that.

I've added the cordova-plugin-splashscreen to my project.

  cordova plugin add cordova-plugin-splashscreen

The splashscreen is still not being displayed - instead a blackscreen turns up when the app runs on the emulator. After a couple of seconds, the blackscreen goes away and the default 'device-ready' Cordova screen appears.

I've done everything suggested in other places - can you guys spot what's wrong?

FYI I was looking at the /plataforms directory and it seems things are correctly set.

The snippet below is from /platforms/android/res/xml/config.xml:

<splash density="land-hdpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="land-ldpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="land-mdpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="land-xhdpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="port-hdpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="port-ldpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="port-mdpi" src="res/drawable-land-xhdpi/screen.png" />
<splash density="port-xhdpi" src="res/drawable-land-xhdpi/screen.png" />
<icon density="ldpi" src="res/screen/android/icon.png" />
<icon density="mdpi" src="res/screen/android/icon.png" />
<icon density="hdpi" src="res/screen/android/icon.png" />
<icon density="xhdpi" src="res/screen/android/icon.png" />

There are screen.png files under every directory listed above - so it seems Cordova is doing its work correctly.


Main activity:

package com.example.hello;

import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}
解决方案

I've struggled with this issue for quite some time too, and found out that the problem is in the values for SplashScreenDelay and FadeSplashScreenDuration.

If you look at SplashScreen.java, you'll find that the showSplashScreen function executes the following:

final int fadeSplashScreenDuration = getFadeDuration();
final int effectiveSplashDuration = Math.max(0, splashscreenTime - fadeSplashScreenDuration);

In your config, you've set the SplashScreenDelay to be 2000 ms.

getFadeDuration looks for the FadeSplashScreenDuration element and when not found (in this case) falls back to the default DEFAULT_SPLASHSCREEN_DURATION, which is 3000 ms, resulting in a negative value for the effectiveSplashDuration. Apparently this will lead to no splashscreen being displayed.

So the solutions are

  • add a FadeSplashScreenDuration element to the configuration with the value set to 0. (or any number smaller than 2000)
  • Increase the value of SplashScreenDelay to 4000 (or any number larger than 3000)

这篇关于科尔多瓦闪屏没有显示在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:49