Custom font for Android listview

后端 未结 2 749
星月不相逢
星月不相逢 2020-11-29 10:01

I have a custom font for my android activity.

MainActivity.class

    private void initControls() {
    // TODO Auto-generated method         


        
2条回答
  •  鱼传尺愫
    2020-11-29 10:24

    Here is the custom adapter class and the constructor

    class CustomAdapter extends ArrayAdapter{
    
        Context context; 
        int layoutResourceId;    
        CharSequence data[] = null;
        Typeface tf; 
    
    public CustomAdapter(Context context, int layoutResourceId, CharSequence[] data, String FONT ) { 
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
        tf = Typeface.createFromAsset(context.getAssets(), FONT);
    }   
    

    Put the font you want to use in your assets folder and fill your listview like this:

    listAdapter = new CustomAdapter(this, R.layout.custom_list_text, R.array.abra_hotel, "name_of_font.ttf");
    

提交回复
热议问题