2
votes

I want to use different font styles. I'am using the following code for different font style. How can i get other styles? Can i have some other styles in same ttf file? Where do i get ttf files of different fonts?

TextView txt = (TextView) findViewById(R.id.custom_font);  
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf"); 
txt.setText("This is sample text with Chantelli Antiqua font style.");
txt.setTypeface(font); 
2

2 Answers

3
votes

If you are looking for only styles with the same font you can add style to your Typeface like this,

txt.setTypeface(font,Style.BOLD);
txt.setTypeface(font,Style.ITALIC); 
txt.setTypeface(font,Style.BOLD_ITALIC);
3
votes

To my knowledge, there is no restriction on how many different fonts you can use in your app. Without getting into the merits of the above statement of course.

I think when you say other styles from TTF files, you mean the bold, italic, normal, medium, etc, styles of a font. The answer is: not from the same TTF file. If you open your Fonts folder in Windows for example, and then open a specific font, you will see multiple files specific to each style. You will need to copy all the files that you need in your app and paste them in your apps "assets/fonts" folder.

Second, if you are looking for fonts installed on your computer, you will find them in your c:\Windows\Fonts folder. If you are looking for more fonts to choose from, you will find a lot on these sites:

http://www.google.com/webfonts

http://www.fontsquirrel.com/