0

following is a code snippet from an app of android where I want to change the font of my listView items. But it doesn't affect:

ListView lv = (ListView) findViewById(R.id.listView);

Typeface tf= Typeface.createFromAsset(getAssets(),"fonts/JAMEEL.TTF"); 

Paint paint = new Paint(tf);
lv.setPaint(paint);

Please tell me how to change the font of listview items.

1 Answers1

1

Use setTypeFace():

Typeface type = Typeface.createFromAsset(getAssets(),"fonts/JAMEEL.TTF"); 
textView.setTypeFace(type); //listview - textview anything

You can also try using Calligraphy library which is easier to set fonts for the whole app.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • i am using listview, not textview... these methods are not available for listview – Tehmina Batool Sep 27 '18 at 09:04
  • 1
    You'll need to override a method in the `ListView` Adapter: https://stackoverflow.com/a/13403769/4409113 But that wasn't my point since you didn't use `setTypeFace()`. Also, it's better to use `RecyclerView` nowadays. – ʍѳђઽ૯ท Sep 27 '18 at 09:06
  • thanks. how to use calligraphy library for listview. is there any specific tutorial? – Tehmina Batool Sep 27 '18 at 09:17
  • 1
    Just add the [dependency](https://github.com/InflationX/Calligraphy#dependency) and follow the [installation](https://github.com/InflationX/Calligraphy#installation). It actually explained everything you need :) – ʍѳђઽ૯ท Sep 27 '18 at 09:19