Custom font for Android listview

后端 未结 2 734
星月不相逢
星月不相逢 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<CharSequence>{
    
        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");
    
    0 讨论(0)
  • 2020-11-29 10:40

    you can't apply font directly to listview and you need to create custom adapter for listview and change it font for more details click below stack post it's already discussed.

    How to change color and font on ListView

    0 讨论(0)
提交回复
热议问题