https://github.com/JoanZapata/android-iconify
dependencies {
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' // (v4.5)
compile 'com.joanzapata.iconify:android-iconify-entypo:2.2.2' // (v3,2015)
compile 'com.joanzapata.iconify:android-iconify-typicons:2.2.2' // (v2.0.7)
compile 'com.joanzapata.iconify:android-iconify-material:2.2.2' // (v2.0.0)
compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.2' // (v1.4.57)
compile 'com.joanzapata.iconify:android-iconify-meteocons:2.2.2' // (latest)
compile 'com.joanzapata.iconify:android-iconify-weathericons:2.2.2' // (v2.0)
compile 'com.joanzapata.iconify:android-iconify-simplelineicons:2.2.2' // (v1.0.0)
compile 'com.joanzapata.iconify:android-iconify-ionicons:2.2.2' // (v2.0.1)
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Iconify
.with(new FontAwesomeModule())
.with(new EntypoModule())
.with(new TypiconsModule())
.with(new MaterialModule())
.with(new MaterialCommunityModule())
.with(new MeteoconsModule())
.with(new WeathericonsModule())
.with(new SimpleLineIconsModule())
.with(new IoniconsModule());
}
}
用 {} 符号将标签包裹起来,即可使用
<com.joanzapata.iconify.widget.IconTextView
android:text="I {fa-heart-o} to {fa-code} on {fa-android}"
android:shadowColor="#22000000"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1"
android:textSize="40sp"
android:textColor="#FF..."
... />
输出结果:
I 爱心图片 to 代码图片 on 安卓图片
调整大小的方式
调整颜色的方式
让图标旋转
// Set an icon in the ActionBar
menu.findItem(R.id.share).setIcon(
new IconDrawable(this, FontAwesomeIcons.fa_share)
.colorRes(R.color.ab_icon)
.actionBarSize());
第一步 需要另外添加依赖
implementation 'com.joanzapata.iconify:android-iconify:2.2.2'
第二步 实现 IconFontDescriptor 类
代码实现如下(assets 目录下有 iconfront.ttf):
FrontIconModule.java
package com.thorn.milk.ec.icon;
import com.joanzapata.iconify.Icon;
import com.joanzapata.iconify.IconFontDescriptor;
public class FrontIconModule implements IconFontDescriptor {
@Override
public String ttfFileName() {
return "iconfront.ttf";
}
@Override
public Icon[] characters() {
return EcIcon.values();
}
}
EcIcon.java 枚举类,其实就是将图标的名称的下划线换成中划线
package com.thorn.milk.ec.icon;
public enum EcIcon implements com.joanzapata.iconify.Icon {
icon_ali_pay('\ue606'),
icon_scan('\ue606');
private char character;
EcIcon(char character) {
this.character = character;
}
@Override
public String key() {
return name().replace('_', '-');
}
@Override
public char character() {
return character;
}
}