android - Cordova - Android 上的自适应图标

标签 android cordova icons fill

我有一组使用 Android Image Asset Studio 生成的图标. 但是,我不知道如何在 Cordova 中为我的应用程序设置这些图标。

当关注 documentation regarding icons in 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 中,应用程序的图标是圆形的,它无法在该手机上正确显示我的应用程序图标。图标缩小到圆圈内,周围有白色背景。

enter image description here

问题:如何将 Image Asset Studio 生成的圆形图标设置到我的 Cordova 项目中?

最佳答案

下面是我的生产项目的经过测试和工作的解决方案。

将所有生成的图标复制到res/android在项目的根目录(与 resourcesplatforms 文件夹相同的级别)并将以下配置添加到 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> .

将上述更改添加到您的 config.xml 后, 使用 ionic cordova platform remove android 删除您的 Android 平台或 sudo ionic cordova platform remove android (取决于您的环境设置)然后使用 ionic cordova platform add android 再次添加 Android 平台或 sudo ionic cordova platform add android .

创建构建、安装并检查结果。

我在生产代码中使用了上述配置,结果如下:

enter image description here

关于android - Cordova - Android 上的自适应图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51691533/

相关文章:

android - 如何为设计支持库的 NavigationView 设置样式?

javascript - AngularJS $http.get ('' 中缺少参数)

cordova - 如何在 Linux 上为 iOS 和 iPhone 构建 Phonegap 应用程序?

C++ OpenGL 程序 - 添加图标

c - 如何更改C语言程序的默认图标?

java - 如何创建动态多维ArrayList?

Android项目如何使用/合并多个AndroidManifest.xml

java - 如何通过加速度传感器移动我的布局?

javascript - 添加 cordova.js 时混合移动应用程序崩溃

ruby-on-rails - 如何将图标与记录链接,但将其显示在远离记录部分的位置?