0

I have a clocktopia font on my android device and it's only on some applications.

How do I use that particular font programmatically?

Thank you.

MKJParekh
  • 34,073
  • 11
  • 87
  • 98

2 Answers2

0

First, put the .ttf (or other font file) in your /assets directory. Then, set the font face of your textview with the following code.

TextView textView = (TextView) findViewById(R.id.myTextView);
Typeface font = Typeface.createFromFile("path-to-file"); 
textView.setTypeface(font);

Unfortunately you cannot use custom typefaces in XML (so you also cannot define a custom theme with your font).

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • How do I find the font on my Android? Do you know which dir it will be in? – Seph Irockthis Jun 21 '12 at 14:40
  • 1
    I was wrong about fonts outside of the apk, and updated my answer as well. If you know the path, you can use [Typeface.createFromFile(String path)](http://developer.android.com/reference/android/graphics/Typeface.html#createFromFile(java.lang.String)) I'm not sure where Clocktopia is located on a device. I would probably just try to find the .ttf and put it in my apk. Also, you may want to check out [this question](http://stackoverflow.com/questions/2973270/using-a-custom-typeface-in-android), which has some more solutions on how to use custom fonts. – Bryan Herbst Jun 21 '12 at 14:45
0

Custom fonts and XML layouts (Android)

You can use the TextViewPlus class provider here to load the typeface from xml but I don't know of a way to use a theme to do this automatically.

Community
  • 1
  • 1
draksia
  • 2,371
  • 2
  • 20
  • 25