应用程序图标仅在 API21 中显示,但在其他 api 中失败

App Icon displayed only in API21 but fails in other api's

我的清单文件中有这段代码。我面临的问题是该图标仅在 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 中的图像有关吗?因为它们看起来不错。甚至清单中行号附近的图标预览看起来也不错。

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

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

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

显然,这是因为 mipmap-anydpi-v26 中缺少 XML 文件。我在 drawable 中有两个 XML 文件。

在其他项目中查找了类似的文件,发现 XML 文件基本上都包含标签,后跟背景和前景标签。

这两个标签的属性基本上是指drawable文件夹下的文件。最有可能的背景是一个布局资源文件,其中包含代表图标背景颜色的标签,而前景将是一个矢量。

但是删除所有 mipmap 并根据 https://developer.android.com/studio/write/image-asset-studio#create-notification 重新生成它们应该也可以。