将文件添加到/ res / values?

时间:2017-03-10 18:04:40

标签: android phonegap-cli

是否可以指定要添加到Android / res / values文件夹的文件?

我正在尝试添加自定义主题以更改原生输入选择器的外观,例如<input type="date">。我找到了cordova-custom-config插件,它允许我在AndroidManifest.xml中设置主题,但这对于实际添加文件没有任何作用

1 个答案:

答案 0 :(得分:0)

想出来:

我在config.xml

中添加了一个钩子到android平台
<hook type="before_prepare" src="scripts/020_copy_resources.js" />

在钩子中,我运行了基于this answer的脚本,保存在<project>/scripts/020_copy_resources.js"

#!/usr/bin/env node

// Native resources to copy
var androidNativePath = 'native/android/';

// Android platform resource path
var androidResPath = 'platforms/android/res/';

// Copy native resources
var rootdir = process.argv[2];

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

function copyFileSync( source, target ) {

    var targetFile = target;

    //if target is a directory a new file with the same name will be created
    if ( fs.existsSync( target ) ) {
        if ( fs.lstatSync( target ).isDirectory() ) {
            targetFile = path.join( target, path.basename( source ) );
        }
    }
    process.stdout.write('Copying ' + source + ' to ' + targetFile);
    fs.writeFileSync(targetFile, fs.readFileSync(source));
}

function copyFolderRecursiveSync( source, target ) {
    var files = [];

    //check if folder needs to be created or integrated
    //var targetFolder = path.join( target, path.basename( source ) );
    var targetFolder = target;
    if ( !fs.existsSync( targetFolder ) ) {
        fs.mkdirSync( targetFolder );
        process.stdout.write('fs.mkdirSync( ' + targetFolder + ' )');
    }

    //copy
    if ( fs.lstatSync( source ).isDirectory() ) {
        files = fs.readdirSync( source );
        files.forEach( function ( file ) {
            var curSource = path.join( source, file );
            if ( fs.lstatSync( curSource ).isDirectory() ) {
                var newTarget = path.join( targetFolder, path.basename( curSource ) );
                copyFolderRecursiveSync( curSource, newTarget );
                process.stdout.write('copyFolderRecursiveSync(' + curSource + ', ' + newTarget + ' )');
            } else {
                copyFileSync( curSource, targetFolder );
                process.stdout.write('copyFileSync(' + curSource + ', ' + targetFolder + ' )');
            }
        } );
    }
}

if (rootdir) {
    copyFolderRecursiveSync(androidNativePath, androidResPath);
    process.stdout.write('Copied android native resources');
}

这会将<project>/native/android中的所有文件/文件夹复制到<project>/platforms/android/res

然后我跟着this answer为日期选择器构建主题。出于我的目的,我只需要在主题和colorAccent中设置colorBackgrounddatePickerDialogTheme