2

I am doing like this but it get force close. I want to change textview font.

TextView mWeddingDataandTime=(TextView)findViewById(R.id.wedding_weddingtime_txt);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/CURLZ_.otf"); 
mWeddingDataandTime.setTypeface(face); 

I am using .otf file. It is in assets folder. Any idea?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
sai
  • 2,562
  • 8
  • 31
  • 46

6 Answers6

1

Try this:

    TextView txt = (TextView) findViewById(R.id.custom_font);
    Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");
    txt.setTypeface(font);

Note that file extension is "ttf" search in google for any font for download in this extension

for example: http://www.creamundo.com/

thenosic
  • 1,463
  • 2
  • 18
  • 22
0

In code you are using fonts/CURLZ_.otf as path but you say that font file is directly inside assets so your code should be

Typeface face=Typeface.createFromAsset(getAssets(),"CURLZ_.otf"); 

if there is no fonts folder inside assets folder.

anujprashar
  • 6,263
  • 7
  • 52
  • 86
0

I didn't test it but I think it may help you:

  TextView mWeddingDataandTime=(TextView)findViewById(R.id.wedding_weddingtime_txt);
  Typeface face=Typeface.createFromAsset(getAssets(),"fonts/CURLZ_"); 
  mWeddingDataandTime.setTypeface(face); 
user
  • 86,916
  • 18
  • 197
  • 190
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
0

Better to make use of the styles and themes and inbuilt fonts for performance related and size of the app related issues Styles & Themes

Suman
  • 4,221
  • 7
  • 44
  • 64
0

If your font is only in asset folder not in asser/fonts forlder than use this

 Typeface face=Typeface.createFromAsset(getAssets(),"CURLZ_.otf"); 
Khan
  • 7,585
  • 3
  • 27
  • 44
0

Below is code which I used in my project & it's working... You might need to do some changes

  Typeface myTypeface = Typeface.createFromAsset(this.getAssets(),"segoeuil.ttf");
  TextView loantext = (TextView)findViewById(R.id.loantext);
  length1.setTypeface(myTypeface);

1) Put font in assets folder instead of fonts folders 2) instead of getAssests() in you code use "this.getAssets()" or "youractivity.this.getAssets()

Thank You

Sandip Jadhav
  • 7,377
  • 8
  • 44
  • 76