先引入:

1
2
compile 'com.joanzapata.iconify:android-iconify-ionicons:2.2.2' // (v2.0.1)
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' // (v4.5)

在Applciation初始化:

Iconify.with(FontAwesomeModule()) .with(FontEcModule())

自定义module使用:先创建继承自IconFontDescriptor的类

1
2
3
4
5
6
7
8
9
10
class FontEcModule : IconFontDescriptor{
override fun ttfFileName(): String {
return "iconfont.ttf"
}

override fun characters(): Array<EcIcons> {
return EcIcons.values()

}
}

上面的ttf文件是放在assets目录下的,之后定义枚举的Icon

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public enum EcIcons implements Icon {
icon_shuidi('\ue600')

;


private char character;

EcIcons(char character) {
this.character = character;
}

@Override
public String key() {
return name().replace('_', '-');
}

@Override
public char character() {
return character;
}
}

这里有个细节,枚举中的名字是用下划线_定义的,但是在使用时要用- 

1
android:text="{icon-shuidi}"

 这里的unicode编码  需要将&#xe删除 改为\u

本文地址: http://www.yppcat.top/2019/05/14/iconify使用/