1.将字库复制到项目下
![](https://img.haomeiwen.com/i14093317/610485de85b36e80.png)
2.自定义TextView
public class SongTiTextView extends android.support.v7.widget.AppCompatTextView{
private Typeface mFace;
public SongTiTextView(Context context) {
super(context);
init(context,null);
}
public SongTiTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public SongTiTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
private void init(Context context,AttributeSet attrs) {
mFace = MyApplication.getInstance().getTypeface();
if(mFace!=null)
this.setTypeface(mFace);
context.obtainStyledAttributes(attrs, R.styleable.SongTiTextView);
if(!attribute.getBoolean(R.styleable.SongTiTextView_tv_use_own_gravity, false)) {
this.setGravity(Gravity.RIGHT);
}
attribute.recycle();
}
}
网友评论