-3

I want to set a custom font by default for TextView in android app. Will i need to create custom view for this ? Or is there any other way to do it except for loading it from assets folder and applying them individually?

Is there a way that a custom font can be directly used in xml, just like "sans","serif"

Tejas
  • 585
  • 3
  • 15

3 Answers3

0

In your asset folder create a folder named fonts and then access it like this :

TextView text = (TextView) findViewById(R.id.textview03);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/YourFile.otf");
text.setTypeface(tf);
CodeWarrior
  • 5,026
  • 6
  • 30
  • 46
0

First download the .ttf file of the font you need (urfont.ttf). Place it in the assets folder(Inside assest folder create new folder named "fonts" and place it inside it).

    Typeface tf = Typeface.createFromAsset(getAssets(),
    "fonts/urcustomfont.ttf");
    TextView tv = (TextView) findViewById(R.id.CustomFontText);
    tv.setTypeface(tf);
ORGL23
  • 434
  • 5
  • 10
0

This question has previously been answered:

How to change the font on the TextView?

Default font is Droid Sans. Also can have Droid Sans Mono and Droid Serif. These can be changed through either using setTypeface, or through editing the android:typeface XML

As already stated, you can use custom fonts by the method described by AndroidWarrior but keep in mind licensing issues as well as the performance of your app if you add lots of custom fonts.

Community
  • 1
  • 1
  • Is there a way that a custom font can be directly used in xml, just like "sans","serif". – Tejas Jul 17 '14 at 07:04