Android 2.3及以上版本支持自定义的ttf字体的方法
所谓无图无真相,先看效果图:
Java代码如下:
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 {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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);
}
}
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class Y_fonts extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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);
}
}
PS:
我使用的字体是华文行楷
由于Android系统对字体文件的支持问题,该字体文件2.3.3版本以上有效,2.2版本不支持。
Android App应用开发者年终总结--日均200元的广告收入
71道经典Android面试题和答案--重要知识点都涉及到了
贡献15本pdf完整版经典Android教程和海量Android源码