MAUI Android配置Material You自适应图标遇编译错误与图标未更新问题
解决MAUI Android Material You自适应图标不生效问题
步骤1:正确放置并配置图标资源
- 将生成工具输出的
res目录下所有子文件夹(如mipmap-anydpi-v26、mipmap-hdpi等),直接复制到项目的Platforms/Android/Resources目录下,覆盖原有对应文件夹。 - 选中所有新添加的图标文件和xml配置文件,右键→属性,将生成操作设置为
AndroidResource,确保构建系统能识别这些资源。
步骤2:修正AndroidManifest.xml配置
修改application节点的图标配置,同时添加圆形图标支持(Material You自适应图标要求):
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"> </application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="33" /> </manifest>
注:如果生成的资源中包含appicon_round相关文件,必须配置android:roundIcon,否则部分设备仍会显示默认图标。
步骤3:调整项目配置,禁用MAUI默认图标生成
打开项目的.csproj文件,修改MauiIcon节点,让Android平台使用自定义资源而非默认SVG生成的图标:
<!-- 非Android平台使用原SVG配置 --> <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'android'" /> <!-- Android平台直接引用自定义自适应图标配置 --> <MauiIcon Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'" Include="Platforms\Android\Resources\mipmap-anydpi-v26\appicon.xml" />
步骤4:彻底清理并重建项目
- 右键项目→清理解决方案
- 手动删除项目根目录下的
bin和obj文件夹 - 重新构建并部署到Android设备
额外排查点
- 确认测试设备系统版本为Android 12(API 31)及以上,Material You自适应图标仅支持该版本及更高系统
- 检查
appicon.xml中引用的前景、背景图标文件名是否与实际文件一致 - 卸载设备上的旧版本应用,避免图标缓存导致显示异常
内容的提问来源于stack exchange,提问作者Veksi
相关产品推荐
相关产品推荐

