參考文章:
android-iconify 使用詳解
IconFont的制作及在Android的使用
在android-iconify的簡單直接使用基礎(chǔ)上進行操作
默認已經(jīng)集成好iconify,可以完成最基本的使用
(1)新建assets文件夾,并將字體文件fontello.ttf拷貝到文件夾下
(2)新建FontelloModule類浪谴,實現(xiàn)IconFontDescriptor接口厕鹃,內(nèi)容如下:
public class FontelloModule implements IconFontDescriptor {
@Override
public String ttfFileName() {
return "fontello.ttf";
}
@Override
public Icon[] characters() {
return FontelloIcons.values();
}
}
(3)新建FontelloIcons枚舉,實現(xiàn)Icon接口册养,內(nèi)容如下:
//關(guān)于fe_spin1('\uE800'):
在ttf文件夾中提供的html文件中的編碼->變成
0xe800 -> ('\uE800')
public enum FontelloIcons implements Icon {
icon_news('\uE800'),
icon_contact('\uE801'),
icon_more('\uE802');//注:這里我并沒有把所有的圖標都加上
char character;
FontelloIcons(char character) {
this.character = character;
}
@Override
public String key() {
return name().replace('_', '-');
}
@Override
public char character() {
return character;
}
}
(4)測試:在activity_main.xml布局文件中添加一個IconTextView
<com.joanzapata.iconify.widget.IconTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shadowColor="#22000000"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1"
android:text="I {icon-news 12dp} to {icon-contact 20dp} on {icon-more 40dp}"
android:textColor="@color/purple"
android:textSize="40sp" />
(5)在Application中添加初始化操作
Iconify.with(new FontelloModule());
完成~