效果图
实现代码:
1、先下载字体文件.ttf
下载链接:http://font.chinaz.com/maobiziti.html
2、main文件夹下创建fonts文件夹,.ttf文件复制到fonts文件夹下
3、读取ttf文件
private void getFontFromAssets() {
mTypefaceList.add(Typeface.DEFAULT);
String[] fontNameList = null;
AssetManager assetManager = getAssets();
try {
fontNameList = assetManager.list("fonts");
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < fontNameList.length; i++) {
String fontPath = "fonts" + "/" + fontNameList[i];
Typeface typeface = Typeface.createFromAsset(assetManager, fontPath);//根据路径得到Typeface
mTypefaceList.add(typeface);
}
}
4、设置文本字体:
textView.setTypeface(mTypefaceList.get(1)); textView2.setTypeface(mTypefaceList.get(2)); textView3.setTypeface(mTypefaceList.get(3)); textView4.setTypeface(mTypefaceList.get(4));