我正在关注文档,为我的图标添加背景颜色。
我用内容创建了colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#742A84</color>
</resources>
并将其保存在
res/values/colors.xml
中,然后添加到配置中
<resource-file src="res/values/colors.xml" target="app/src/main/res/values/colors.xml" />
最后设置每个图标的颜色,如
<icon density="ldpi" background="@color/background" foreground="res/icons/android/icon-36.png" />
但是当我这样做时
cordova build android
,我明白了
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('ENOENT')
at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
at C:\Users\Eric\AppData\Roaming\npm\node_modules\cordova\bin\cordova:32:22
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
我什至尝试了
cordova platform rm android
然后cordova platform add android
,然后我得到了
One of the following attributes are set but missing the other for the density type: ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi.
删除每个图标的
background="@color/background"
并删除
<resource-file src="res/values/colors.xml" target="app/src/main/res/values/colors.xml" />
然后构建应用程序。我检查了
app/src/main/res/values/
,colors.xml 丢失了。
我做错了什么?或者这是 Cordova 的另一个半生不熟的功能?
我会用我自己的工作来回答我自己的问题。
由于我使用与初始屏幕相同的颜色,因此我绕过了添加资源文件的步骤并重新使用初始屏幕颜色。
<icon density="ldpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-36.png" />
<icon density="mdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-48.png" />
<icon density="hdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-72.png" />
<icon density="xhdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-96.png" />
<icon density="xxhdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-144.png" />
<icon density="xxxhdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-192.png" />