public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Typeface font = Typeface.createFromAsset(
getAssets(), "DejaVuSans.ttf");
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
getGroups()));
tv = (TextView)findViewById(R.id.textitem);
//Uncomment a line below and the app crashes!!
//tv.setTypeface(font);
//tv.setGravity(Gravity.LEFT);
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textitem"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:gravity="right"
/>
问题是我想在ListView中为TextView设置一个新的字体,似乎无法在XML文件中完成!!