android - Cordova - Android 上的自适应图标
问题描述
我有一组使用Android Image Asset Studio生成的图标。但是,我不知道如何将这些图标设置到我的应用程序中Cordova
。
在遵循有关 Cordova 中图标的文档时,我只设法使用以下代码将方形图标设置为我的项目:
<platform name="android">
<!--
ldpi : 36x36 px
mdpi : 48x48 px
hdpi : 72x72 px
xhdpi : 96x96 px
xxhdpi : 144x144 px
xxxhdpi : 192x192 px
-->
<icon src="res/android/ldpi.png" density="ldpi" />
<icon src="res/android/mdpi.png" density="mdpi" />
<icon src="res/android/hdpi.png" density="hdpi" />
<icon src="res/android/xhdpi.png" density="xhdpi" />
<icon src="res/android/xxhdpi.png" density="xxhdpi" />
<icon src="res/android/xxxhdpi.png" density="xxxhdpi" />
</platform>
但是,假设在 Android Oreo 中,应用程序的图标是圆形的,并且在该手机上无法正确显示我的应用程序图标。图标在圆圈内缩小,周围有白色背景。
问题:如何将 Image Asset Studio 生成的圆形图标设置到我的 Cordova 项目?
解决方案
以下是我正在生产的项目的经过测试且有效的解决方案。
将所有生成的图标复制到res/android
项目的根目录(与文件夹相同的级别)并将以下配置添加到resources
文件中:platforms
config.xml
<widget xmlns:android="http://schemas.android.com/apk/res/android">
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" />
</edit-config>
<resource-file src="res/android/drawable/ic_launcher_background.xml" target="app/src/main/res/drawable/ic_launcher_background.xml" />
<resource-file src="res/android/mipmap-hdpi/ic_launcher.png" target="app/src/main/res/mipmap-hdpi/ic_launcher.png" />
<resource-file src="res/android/mipmap-hdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-hdpi/ic_launcher_round.png" />
<resource-file src="res/android/mipmap-mdpi/ic_launcher.png" target="app/src/main/res/mipmap-mdpi/ic_launcher.png" />
<resource-file src="res/android/mipmap-mdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-mdpi/ic_launcher_round.png" />
<resource-file src="res/android/mipmap-xhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xhdpi/ic_launcher.png" />
<resource-file src="res/android/mipmap-xhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xhdpi/ic_launcher_round.png" />
<resource-file src="res/android/mipmap-xxhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xxhdpi/ic_launcher.png" />
<resource-file src="res/android/mipmap-xxhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png" />
<resource-file src="res/android/mipmap-xxxhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher.png" />
<resource-file src="res/android/mipmap-xxxhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png" />
</platform>
</widget>
不要忘记添加xmlns:android="http://schemas.android.com/apk/res/android"
到您的<widget>
.
<icon>
如果你有一个<widget>
=> <platform
=> ,请删除<icon>
。
将上述更改添加到您的 后,使用orconfig.xml
删除您的 Android 平台(取决于您的环境设置),然后使用or再次添加 Android 平台。ionic cordova platform remove android
sudo ionic cordova platform remove android
ionic cordova platform add android
sudo ionic cordova platform add android
创建构建,安装并检查结果。
我在生产代码中使用了上述配置,结果如下:
推荐阅读
- c++ - 如何使用 Pybind11 将图像(cv::Mat)从 C++ 发送到 Python?
- php - 使用 PHP 显示每种类型的列
- kernel - 从 Beaglebone black 中的 eMMc 启动时如何更改内核映像?
- c++ - 编译时 G++ 未找到包含的 .cpp 文件
- python - 为什么 Python 在字符串中添加额外的字符?
- python - 如何在不和谐中创建基本命令然后附加组件?我正在使用蟒蛇
- python - 多处理后管理打印输出顺序
- opencv - 如何删除所选轮廓OpenCV之外的区域
- html - 如何在 Ionic 4 中显示 html 文件
- pci - DVSEC、VSEC 和 RCRB 的区别