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
  • 88,437
  • 31
  • 141
  • 199
sai
  • 2,582
  • 7
  • 30
  • 45

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,445
  • 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,250
  • 6
  • 48
  • 82
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,378
  • 18
  • 196
  • 190
Md Abdul Gafur
  • 6,169
  • 2
  • 26
  • 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,121
  • 7
  • 43
  • 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,545
  • 3
  • 26
  • 43
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,217
  • 8
  • 43
  • 75