How to set font in textview in android?

I do so, but he's getting closer to strength. 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 the .otf

file. It is located in the assets folder. Any idea?

+3


source to share


6 answers


Try the following:

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

      



Please note that the file extension is "ttf" google search for any font to download in that extension

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

+1


source


In your code, you are using fonts/CURLZ_.otf

as a path, but you are saying that the font file is directly inside the assets, so your code should be

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

      



if there is no font folder in the resource folder.

0


source


I haven't tested it, but I think this might help you:

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

      

0


source


Better to use styles and themes and inline fonts for performance and sizing-related application-related issues Styles and themes

0


source


If your font is only found in the assets folder and not in the root of the fonts / fonts then use

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

      

0


source


Below is the code I used in my project and it works ... You may need to make some changes.

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

      

1) Put the font in the folder with folders instead of font folders 2) instead of getAssests () in your code use "this.getAssets ()" or "youractivity.this.getAssets ()

thank

0


source







All Articles