1. 现代推荐方法:使用自适应图标
只需要 2 个文件:
res/
├── mipmap-anydpi-v26/
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
├── drawable/
│ ├── ic_launcher_foreground.xml
│ └── ic_launcher_background.xml
AndroidManifest.xml 配置:
<application
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name">
系统会自动为不同分辨率生成适配的图标。
2. 最简单的方案:使用 Android Studio 的 Image Asset Studio
这是 最推荐 的方法:
- 右键点击
res目录 → New → Image Asset - 选择 Launcher Icons (Adaptive and Legacy)
- 上传一张 高分辨率图片(建议 512×512 或更大)
- Android Studio 会 自动生成所有需要的尺寸
生成的文件结构:
res/
├── mipmap-hdpi/
├── mipmap-mdpi/
├── mipmap-xhdpi/
├── mipmap-xxhdpi/
├── mipmap-xxxhdpi/
└── mipmap-anydpi-v26/
你只需要提供一张源图片,工具会自动处理所有尺寸!
3. 如果只放一个尺寸会发生什么?
测试结果:
- 只放 xxxhdpi (192×192):在大多数现代设备上显示正常
- 只放 xxhdpi (144×144):在高分辨率设备上可能模糊
- 只放 mdpi (48×48):在高分辨率设备上会非常模糊
示例(只使用最大尺寸):
<!-- AndroidManifest.xml -->
<application
android:icon="@mipmap/ic_launcher_xxxhdpi"
android:roundIcon="@mipmap/ic_launcher_round_xxxhdpi"
android:label="@string/app_name">
系统会尝试自动缩放,但结果可能不理想:
- ✅ 应用能正常安装运行
- ⚠️ 在某些设备上图标可能模糊
- ⚠️ 在低内存设备上可能有性能问题
4. 最小化方案(生产环境不推荐)
如果只是为了快速测试,可以只提供 2-3 个关键尺寸:
res/
├── mipmap-xxxhdpi/ic_launcher.png (192×192)
├── mipmap-xxhdpi/ic_launcher.png (144×144)
└── mipmap-anydpi-v26/ic_launcher.xml (自适应图标)
5. 实际项目中的最佳实践
方案 1:使用自适应图标(推荐)
<!-- res/mipmap-anydpi-v26/ic_launcher.xml -->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
方案 2:使用 SVG 矢量图
<!-- res/drawable/ic_launcher.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF0000"
android:pathData="M12,2L13,8L20,8L15,12L17,18L12,14L7,18L9,12L4,8L11,8Z"/>
</vector>
然后在 AndroidManifest 中引用:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
6. 总结
| 方法 | 所需文件 | 推荐度 | 说明 |
|---|---|---|---|
| Image Asset Studio | 1 张源图片 | ⭐⭐⭐⭐⭐ | 全自动,生成所有尺寸 |
| 自适应图标 | 2个XML文件 | ⭐⭐⭐⭐ | 现代方法,Android 8.0+ |
| SVG 矢量图 | 1个XML文件 | ⭐⭐⭐ | 简单图标适用 |
| 只放最大尺寸 | 1个PNG文件 | ⭐ | 仅测试用,生产环境不推荐 |
生产环境建议:直接使用 Android Studio 的 Image Asset Studio,它是最简单、最可靠的方法,能确保在所有设备上都有良好的显示效果。

1809

被折叠的 条评论
为什么被折叠?



