简体   繁体   中英

Set font of custom ListActivity in Android

I have a custom ListActivity that acts as a multiple choice question, and I am trying to change the font of the items in the list. Here's what I have...

public class MultipleChoiceActivity extends ListActivity {

private TextView questionView;
private String[] items = { "a", "b", "c", "d" };

@Override
public void onCreate(Bundle savedInstanceState) {
    //do some stuff like populate items array from db

    setContentView(R.layout.multichoice_activity);
    setListAdapter(new ArrayAdapter(this, R.layout.custom_list_item, items));
    questionView = (TextView) findViewById(R.id.question);
    Typeface typeFace=Typeface.createFromAsset(getAssets(),"fonts/Schalk.ttf");
    questionView.setText(question);
    questionView.setTypeface(typeFace);
}

public void onListItemClick(ListView parent, View v, int position, long id) {
    userAnswer = position + 1;
}

So I have been able to set the TextView named "question" with the correct font from my assets, but I haven't been able to use that asset to set it for the elements in the list. Any ideas?

You need to set the TypeFace for each specific view you want. Usually this means, at a bare minimum, you need to set the TypeFace for each view in the adapter as opposed to the ListView itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM