我创建了一个带有自己启动器图标的Android应用程序。它在Nougat版本上运行良好。但是在Oreo版本中,我的图标被默认的Android图标所替换。
我已经在各种分辨率的mipmap资源中定义了ic_launcher.png
和ic_launcher_round.png
,但是问题依然存在。
我的清单文件包含以下行:
android:roundIcon="@mipmap/ic_launcher_round"
我该如何在Oreo上显示我自己的图标?
我创建了一个带有自己启动器图标的Android应用程序。它在Nougat版本上运行良好。但是在Oreo版本中,我的图标被默认的Android图标所替换。
我已经在各种分辨率的mipmap资源中定义了ic_launcher.png
和ic_launcher_round.png
,但是问题依然存在。
我的清单文件包含以下行:
android:roundIcon="@mipmap/ic_launcher_round"
对于API 26+,默认的Android应用程序模板定义了另一个图标资源文件夹
mipmap-anydpi-v26
该文件夹(通常)包含两个xml
文件ic_launcher
和ic_launcher_round
,它们与在API 26+中在清单中声明的图标资源相匹配
这些文件的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
为了拥有自己的图标,您还需要更改所有列出的可绘制项(在所有密度桶中),即 ic_launcher_background
和 ic_launcher_foreground
。或者,您可以直接删除该文件夹,在这种情况下,Android 将回退使用您的 PNG 图标,但它们不会完全呈现,并且通常会在白色背景上绘制。详细信息请参见:自适应图标。最佳解决方案是删除mipmap-anydpi-v26文件夹,然后应用程序将采用默认图标。在Android Studio项目模式下,转到以下包:
res/mipmap-anydpi-v26
删除它并重新构建和运行项目。