Different TTF files for different font in android

◇◆丶佛笑我妖孽 提交于 2019-12-11 04:47:15

问题


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); 

回答1:


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);



回答2:


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/



来源:https://stackoverflow.com/questions/10680046/different-ttf-files-for-different-font-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!