2016-07-27 83 views
3

我在Cordova(6.2)上安装了一个应用程序并将其安装到Android设备(Android v6.0)中。要更改应用程序图标,我需要更换/platforms/android/res/drawable-hdpi中的图标,它工作正常。但是当我添加Android上的闪屏不起作用

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

到config.xml并重新编译应用程序 - 闪屏未显示。

如何解决这个问题? (所有默认的屏幕存在于文件夹,他们的名字screen.png

+0

你有没有通过https://github.com/apache/cordova-plugin-splashscreen? – Naitik

+0

@Naitik是的,启动屏幕cordova插件工作正常。但正如在cordova文档中,它不是必需的,cordova内置了启动画面(这在iOS中没有问题)。我的问题是关于这个内置的启动画面,这不适用于Android。在cordova的官方文档上的 – Evgeniy

+0

也提到https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/index.html,您需要使用插件并创建具有给定大小的启动屏幕。 – Naitik

回答

3

首先安装插件闪屏用以下命令:

科尔多瓦插件添加科尔多瓦 - 插件,闪屏

然后在config.xml中复制以下内容:

Android版:

<platform name="android"> 

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

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

对于IOS:

<platform name="ios"> 
    <splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/> 
    <splash src="res/screen/ios/[email protected]~iphone.png" width="640" height="960"/> 
    <splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/> 
    <splash src="res/screen/ios/[email protected]~ipad.png" width="1536" height="2048"/> 
    <splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/> 
    <splash src="res/screen/ios/[email protected]~ipad.png" width="2048" height="1536"/> 
    <splash src="res/screen/ios/[email protected]~iphone.png" width="640" height="1136"/> 
    <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/> 
    <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/> 
    <splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/> 
</platform> 

现在启动画面与上述尺寸。你可以用多种方式来进行:

1)http://ionicframework.com/docs/cli/icon-splashscreen.html

2)http://ticons.fokkezb.nl/

现在把所有生成的文件中res/screen/{platform}文件夹,并用config.xml中的条目仔细检查

现在再去config.xml并添加以下内容:

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

以上标签隐藏启动屏幕后3 seconds

如果您仍然遇到问题,请给我打电话。

希望它会有所帮助。

+0

我已经安装了启动画面插件,它在Android上正常工作。但我感兴趣的是为什么在iOS启动画面没有cordova-plugin-splashscreen安装的情况下工作,而在Android中则没有。在Android中的 – Evgeniy

+0

将工作,但然后你需要使Java活动。在IOS中,它将为ios和** XCODE **资产设置的午餐图像使用IOS本机在场景后面启动屏幕。在android中有可绘制的文件夹,其中所有的启动画面存储在哪个android内部与闪屏插件。现在是白色还是空白。所以更好地做出改变,就像我在回答中提到的那样,让事情起作用 – Naitik

+0

谢谢你的回答 – Evgeniy

0
public class SplashScreen extends Activity { 
    private static int SPLASH_TIME_OUT = 3000; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splashscreen); 

     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       Intent i = new Intent(SplashScreen.this,GetStartedScreen.class); 
       startActivity(i); 
       finish(); 
      } 
     }, SPLASH_TIME_OUT); 
    } 
} 
+0

SPLASH_TIME_OUT变量你想添加什么时间在毫秒。 – Nirmit

+0

我可以在哪里放置这段代码? – Evgeniy

+0

在您的splase屏幕活动 – Nirmit

0

当我将CLI更新到6.5.0并且插件的较旧版本不支持最新版本后,将不会显示初始屏幕。 所以我删除旧的一个(科尔多瓦 - 插件,闪屏3.2.2“闪屏”),并加入最新一期()

要删除的插件使用方法:

cordova plugin remove cordova-plugin-splashscreen

添加的插件使用方法:

cordova plugin addcordova-plugin-splashscreen