您的位置:首页 > 移动开发 > Android开发

Android 使用字体图标

2017-03-09 15:17 204 查看
将图标做成.ttf字体文件,代替传统的图片资源。

效果



使用

将字体文件导入assets目录



定义字体图标枚举类

这里使用的StringDef注解

@StringDef({IconFonts.AVATAR, IconFonts.SEND})
public @interface IconFonts {
String AVATAR = "\ue662";
String SEND = "\ue79a";
}


调用:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.text_view);
//设置字体
Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/iconfont.ttf");
textView.setTypeface(fontFace);
textView.setText(IconFonts.SEND);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 字体