是否可以在config.xml中的Cordova 3.5中定义启动画面?

时间:2014-07-08 23:48:29

标签: android ios xml cordova

我很难找到文档来检查是否可以使用config.xml定义启动画面?

我没有跟踪Git上的./platform目录,因此我放在那里的任何内容都只能在我的计算机上使用,而不能在其他团队成员中使用。

我想做一些看起来像这样的事情:

<gap:splash gap:density="ldpi" gap:platform="android" src="res/screen/android/screen-ldpi-portrait.png" />
<gap:splash gap:density="mdpi" gap:platform="android" src="res/screen/android/screen-mdpi-portrait.png" />
<gap:splash gap:density="hdpi" gap:platform="android" src="res/screen/android/screen-hdpi-portrait.png" />
<gap:splash gap:density="xhdpi" gap:platform="android" src="res/screen/android/screen-xhdpi-portrait.png" />
<gap:splash gap:platform="blackberry" src="res/screen/blackberry/screen-225.png" />

可能的?

1 个答案:

答案 0 :(得分:0)

好吧,既然我没有得到这个问题的答案,我将发布适用于我的解决方案。

使用Cordova的钩子(after_prepare)我能够将启动画面文件从/www复制到正确的Android和iOS平台目录。

钩子位于/hooks/after_prepare/030_resource_files.js,并且在准备步骤之后由Cordova执行。

这就是我的代码最后的样子:

#!/usr/bin/env node

// Reference: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/

//
// This hook copies various resource files from our version control system directories into the appropriate platform specific location
//

var appName = "MyAwesomeApp";

// configure all the files to copy.  Key of object is the source file, value is the destination location.  It's fine to put all platforms' icons and splash screen files here, even if we don't build for all platforms on each developer's box.
var filestocopy = [{
  "www/res/screens/android/drawable/splash.png": "platforms/android/res/drawable/splash.png"
},{
  "www/res/screens/android/drawable-hdpi/splash.png": "platforms/android/res/drawable-hdpi/splash.png"
}, {
  "www/res/screens/android/drawable-ldpi/splash.png": "platforms/android/res/drawable-ldpi/splash.png"
}, {
  "www/res/screens/android/drawable-mdpi/splash.png": "platforms/android/res/drawable-mdpi/splash.png"
}, {
  "www/res/screens/android/drawable-xhdpi/splash.png": "platforms/android/res/drawable-xhdpi/splash.png"
}, {
  "www/res/screens/ios/Resources/splash/Default@2x~iphone.png": "platforms/ios/" + appName + "/Resources/splash/Default@2x~iphone.png"
}, {
  "www/res/screens/ios/Resources/splash/Default-568h@2x~iphone.png": "platforms/ios/" + appName + "/Resources/splash/Default-568h@2x~iphone.png"
}, {
  "www/res/screens/ios/Resources/splash/Default~iphone.png": "platforms/ios/" + appName + "/Resources/splash/Default~iphone.png"
}];

var fs = require('fs');
var path = require('path');

// no need to configure below
var rootdir = process.argv[2];

filestocopy.forEach(function(obj) {
  Object.keys(obj).forEach(function(key) {
    var val = obj[key];
    var srcfile = path.join(rootdir, key);
    var destfile = path.join(rootdir, val);
    //console.log("copying "+srcfile+" to "+destfile);
    var destdir = path.dirname(destfile);
    if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
      fs.createReadStream(srcfile).pipe(fs.createWriteStream(destfile));
    }
  });
});

仍然很难让它工作,因为有很多部分必须适合它才能工作,但它是帮助我解决问题的钩子。

来源:Holly Schinsky撰写的文章中的复制图标和启动画面部分非常有用,我从中获取了大部分代码:http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/