1,下载字体包 http://www.3987.com/xiazai/6/fonts/36616.html#down
2. studio中srcmain创建assetsfonts,存放字体包
3. 两种使用方法:
<1.只是app中某一块需要使用特定的字体:
TextView tv= (TextView) findViewById(R.id.tv);
Typeface face= Typeface.createFromAsset(getAssets(), "fonts/kaiti.ttf");
tv.setTypeface(face);
<2.整个app字体都要使用特定字体:
这种情况下如果还用第一种方法给每个TextView设置Typeface 就太麻烦了;
这种情况下可用用自定义控件继承,TextView ,在控件中初始化设置TypeView;
package com.example.harvey.frontpagedemo.view;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Created by Harvey on 2016/4/15.
*/
public class CustomFontTextView extends TextView{
public CustomFontTextView(Context context) {
super(context);
init(context);
}
public CustomFontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
AssetManager assetManager= context.getAssets();
Typeface typeface=Typeface.createFromAsset(assetManager, "fonts/kaiti.ttf");//楷体
// Typeface typeface=Typeface.createFromAsset(assetManager, "fonts/shoujin.ttf");//瘦金体
// Typeface typeface=Typeface.createFromAsset(assetManager,"fonts/fangzhengguli.ttf");//方正古隶
// Typeface typeface=Typeface.createFromAsset(assetManager,"fonts/jinglei.ttf");//方正静蕾简体
// Typeface typeface=Typeface.createFromAsset(assetManager,"fonts/pop.ttf");//pop字体
setTypeface(typeface);
}
}
4. 字体包不小......