<Android特效>Fontinator
Fontinator
介绍:
介绍:
Fontinator是一个让使用自定义字体更方便的安卓库。
运行效果:
?
使用说明:
1. 把字体添加到/assets/fonts 目录
2. 把此项目导入为Module
3. 在Application Gradle文件中添加compile project(‘:fontinator‘)?
?
添加?xmlns:app到xml布局的根节点
?xmlns:app="http://schemas.android.com/apk/res-auto"
?
工作原理
Fontinator继承了基于TextView的安卓控件,比如Button,注入一个Cached Fontface loader。
问题
安卓的布局编辑器无法预览自定义字体。
根据基于TextView的控件制作一个自定义控件
选择 1: 就是继承
选择 2:使用TypefaceLoader和Typefaceable接口
?
import?de.morrox.fontinator.utilities.TypefaceLoader;
import?de.morrox.fontinator.utilities.Typefaceable;
?
public?class?MyCustomFontButton?extends?Button?implements?Typefaceable{
????private?TypefaceLoader?typefaceLoader;
????public?FontButton(Context?context,?AttributeSet?attrs)?{
????????super(context,?attrs);
????????typefaceLoader?=?new?TypefaceLoader(this,?context,?attrs);
????}
?
????@Override
????public?void?setText(CharSequence?text,?BufferType?type)?{
????????super.setText(text,?type);
????????if(type?!=?BufferType.SPANNABLE?&&?typefaceLoader?!=?null){
????????????typefaceLoader.createLetterSpacing(text);
????????}
????}
}
运行效果:
原文:http://1105824194.iteye.com/blog/2240182