You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为MAUI应用启用Android端Material You图标?

在.NET 7 Android应用中实现Material You自适应配色图标

一、核心前提说明

Material You的自适应图标依赖Android 12(API 31)及以上系统的自适应图标机制,所以首先确保项目的targetSdkVersion ≥ 31,同时图标必须拆分为「前景(图标主体)」和「背景(可变色底色)」两个独立图层。

二、准备符合要求的图标资源

  • 前景图标:使用透明背景的矢量图(推荐)或PNG,尺寸建议86x86dp(适配多屏幕密度),命名为ic_launcher_foreground.xml(矢量)或ic_launcher_foreground.png,放置在Resources/drawable或对应密度的drawable-xxxhdpi等目录。
  • 背景资源:若要跟随Material You配色自动变化,需使用系统主题属性定义背景。创建ic_launcher_background.xml放在drawable目录,示例内容:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="?android:colorPrimary" /> <!-- 绑定系统主题主色 -->
    <corners android:radius="24dp" /> <!-- 符合Material You圆角规范 -->
</shape>

三、配置自适应图标定义文件

在Resources/mipmap-anydpi-v26目录下创建(或修正)ic_launcher.xml,严格遵循Android自适应图标格式:

<?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>

注意:目录名mipmap-anydpi-v26拼写必须准确,Android资源目录区分大小写

四、修正AndroidManifest.xml配置

确保application标签正确引用自适应图标,并指定符合要求的targetSdkVersion:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application 
        android:allowBackup="true" 
        android:icon="@mipmap/ic_launcher" 
        android:roundIcon="@mipmap/ic_launcher_round" <!-- 可选,适配圆形图标场景 -->
        android:supportsRtl="true"
        android:targetSdkVersion="33"> <!-- 至少31,推荐33+ -->
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

如果是.NET MAUI项目,还需在Platforms/Android/Resources/values/styles.xml中确保主题继承自Material3:

<style name="MyTheme" parent="Theme.Material3.DayNight.NoActionBar">
    <!-- 其他主题配置 -->
</style>

五、常见问题排查

  • 测试设备必须是Android 12及以上版本,低版本系统不支持Material You自适应配色。
  • 前景图标必须是透明背景,否则会遮挡自适应背景色。
  • 清理项目缓存:删除bin和obj目录后重新构建,避免资源缓存导致的不生效。

内容的提问来源于stack exchange,提问作者Tudi Fruity

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 19:30:39