首页 > 解决方案 > 应用程序图标仅在 API21 中显示,但在其他 api 中失败

问题描述

我的清单文件中有此代码。我面临的问题是该图标仅显示在 Android Lollipop (Api21,Asus Nexus Tab)中。我已经在 Oreo (Oppo A3S) 和 Android P (Samsung Galaxy S10+) 中进行了测试,但没有显示图标。mipmap 中的图像看起来不错。

 <application
        android:name=".Application"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">

仅显示纯色(图标的背景)。这与mipmap中的图像有关吗?因为它们看起来不错。即使清单中行号附近的图标预览看起来也不错。

我还观察到我只有一个 webp 文件,mipmap-anydpi-v26但其他应用程序有 2 个 XML 文件,一个用于圆形文件,一个用于普通文件。

标签: androidkotlinandroid-manifestandroid-iconsandroid-mipmap

解决方案


您应该以正确的方式添加启动器图标。首先从 mipmap 中删除所有 ic_launcher 及其所有版本。现在创建图标类型为启动器图标(仅限旧版)或(自适应和旧版)的新图像资产。然后将其命名为 ic_launcher 并选择您的图像路径并设置填充、颜色等,然后​​下一步并完成。它会自动将资产作为清单中的启动器图标。如果不手动设置。

android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"

推荐阅读