一、
所謂無圖無真相,先看效果圖:
二 、代碼:
package yc.android.fonts;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public
class Y_fonts extends Activity {
/** Called when the activity is first created.
*/
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*
* 必須事先在assets底下創建一fonts文件夾 並放入要使用的字體文件(.ttf)
* 並提供相對路徑給creatFromAsset()來創建Typeface對象
*/
Typeface fontFace = Typeface.createFromAsset(getAssets(),
"fonts/STXINGKA.TTF");
// 字體文件必須是true type font的格式(ttf);
// 當使用外部字體卻又發現字體沒有變化的時候(以 Droid Sans代替),通常是因爲
// 這個字體android沒有支持,而非你的程序發生了錯誤
TextView text = (TextView) findViewById(R.id.ttf);
text.setTypeface(fontFace);
}
}
轉自:http://www.cnblogs.com/yc-755909659/archive/2012/04/01/2429363.html