如何修复Android Studio中“Monochrome icon is not defined”警告?
修复「Monochrome icon is not defined」自适应图标错误
你遇到的这个错误是因为Android 13及以上版本的主题化应用图标要求提供单色版本,而你的配置里同时存在android:icon和android:roundIcon,但其中至少一个没有指定单色图标。下面是两种直接的修复方法:
方法一:移除多余的android:roundIcon属性
打开你的AndroidManifest.xml文件,找到<application>标签,删掉其中的android:roundIcon="@mipmap/ic_launcher_round"这一行。
保留android:icon="@mipmap/ic_launcher"即可——系统会自动根据启动器的需求,从自适应图标资源中生成圆形版本,不需要单独指定roundIcon。
方法二:为两个图标都添加单色资源
如果你需要同时保留android:icon和android:roundIcon,就得给它们对应的自适应图标文件都加上单色图标配置:
- 先准备一张单色的图标资源(建议用矢量图,比如
ic_launcher_monochrome.xml) - 打开
res/mipmap-anydpi-v26/ic_launcher.xml和ic_launcher_round.xml(这两个是自适应图标的定义文件) - 在每个文件的
<adaptive-icon>标签内,添加<monochrome>标签指向你的单色资源:
<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"/> <!-- 新增单色图标配置 --> <monochrome android:drawable="@drawable/ic_launcher_monochrome"/> </adaptive-icon>
这样启动器在需要主题化图标时,就能找到对应的单色版本,错误也就解决了。
内容的提问来源于stack exchange,提问作者ronenfe
相关产品推荐
相关产品推荐

