2
AssetManager mgr=getAssets();
Typeface tf=Typeface.createFromAsset(mgr, "fonts/cube.ttf");
textView.setTypeface(tf);

The method above can modify font of the TextView, but I do not want to do it like this. My idea: The user can download the font on the internet and store it in the sd-card. Then the user can apply the font they just downloaded to the widget. I feel this method can reduce the size of the project. Any suggestions?

Leigh
  • 28,765
  • 10
  • 55
  • 103
xmliu
  • 253
  • 1
  • 5

1 Answers1

2

1.) Download "font.ttf" (Replace with your ttf file name) File to external storage through the internet.

2.) Do this.

 Typeface typeface = Typeface.createFromFile(
        new File(Environment.getExternalStorageDirectory(), "font.ttf"));
 textView.setTypeface(tf);
Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
  • thanks,but i don`t know how to download fonts from the internet,can you give me some examples or methods – xmliu Jul 19 '13 at 03:07
  • You'll need a webserver hosting your fonts or find a host with free downloadable fonts with URL exposed (Check out http://www.fontsquirrel.com/blog/2010/12/the-font-squirrel-api). Then just call the URL to download your font in an asynctask and download the file like mentioned here: http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog – Vrashabh Irde Jul 19 '13 at 03:11
  • i'm using eclipse and i have font in particular folder but when i'm trying to set typeface with above solution always get "Native typeface cannot be made" on any device any help? – Ajay Pandya Apr 21 '15 at 13:15