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);
}
}