1. 定義包含1 TextView 布局:main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
/>
</LinearLayout>
2. 下載字型檔 尾碼名一般為:*.ttf 如:本例為:biscuit_tin.ttf
* 在工程目錄下的 assets 目錄下建立檔案夾:fonts 然後把*.ttf檔案 複製至該目錄 並重新整理工程
public class MyTextTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/biscuit_tin.ttf");
TextView text = (TextView)findViewById(R.id.text);
text.setTypeface(fontFace);
text.setText("Hello World!");
text.setTextSize(100);
}
}
考慮著作權問題 *.ttf 字型檔 要大家自己找了 網路上有很多 我一直在找 微軟雅黑 可惜失敗 題外話 microsoft-vista 的貢獻也僅於此了....
emulator 運行: text="Hello World!"