1.字体提取工具
通常为了美观我们很多时候嵌入的字体只需要部分文字即可,没有必要嵌入全字库,可以只提取部分字库。
https://github.com/forJrking/FontZip
2.嵌入到android应用中
Android的Assets类有单个文件1MB体积的限制,将字体文件test.ttf放到工程的assets文件夹的fonts目录中。
package org.yftx.font;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class MainAcitity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface textFont = Typeface.createFromAsset(getAssets(), "fonts/test.ttf");
TextView testView = (TextView) findViewById(R.id.textView2);
testView.setTypeface(textFont); // 设置TextView的风格
testView.setTextSize(12);
testView.setTextColor(Color.RED);
}
}