人升开发日志#3 | 6/8 自适应图标

将开发日志#1做的图标加入到应用中,但是 Android O 加入了一个叫做 Adaptive Icons 的特性,为了适配这个性质稍微有点麻烦。


设置AndroidManifest.xml

AndroidManifest.xml<application后面加上

1
2
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"

icon 指的是普通图标

roundIcon 指的是圆形图标


存入各个规格的PNG图片适配旧版本

mipmap-hdpimipmap-mdpimipmap-xhdpi等各种规格的图片放入 res\ 中。

然后新建一个文件夹 mipmap-anydpi-v26,里面新建一个 ic_launcher.xml 文件。

文件内容如下:

1
2
3
4
5
<?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>

最后文件结构:


分离 SVG 前/背景

利用矢量图编辑工具,将前景保存为 ic_launcher_foreground.svg,背景为ic_launcher_background.svg

然后将 背景SVG 转换成 VectorDrawable 并且放到 res/drawable文件夹内:

直接在 AS 中 res/drawable文件夹上右键→ NewVector Asset就能将 svg 转换成 VectorDrawable 并且放到里面了。


参考

Adaptive Icons - Android O 自适应图标简单用法

理解 Android 的「自适应图标」

人升开发日志#3 | 6/8 自适应图标

http://sarasarasa.net/post/eac283fe.html

作者

AyagiKei

发布于

2018-06-08

更新于

2021-08-10

许可协议

评论