public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Typeface font = Typeface.createFromAsset(
getAssets(), "DejaVuSans.ttf");
setListAdapt开发者_开发知识库er(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"
/>
The problem is that I want to set a new typeface for the TextView in the ListView, and it seems it can't be done in the XML file!!
You can create the custom Adapter and can set the font face in that adapter. Here is one workable solution.
精彩评论