I would like to have an app include a custom font for rendering text, load it, and then use it with standard elements like StaticText. Is this possible?
Asked
Active
Viewed 5.2k times
3 Answers
140
Yes you can, you jsut can't define it into xml layouts. You need to use it dynamically each time. Check this tutorial for instance.
In case link is dead, here is a sum up of the stuff :
- Get a font file like
times.otf
- Drop it in your asset folder, inside a "fonts" folder
Get a reference of TextView with something like that:
TextView tv = (TextView) findViewById(R.id.myCustomTVFont);
Grab you font from the asset folder:
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/times.otf");
Make your TextView look great:
tv.setTypeface(tf);
-
12Hope the tutorial won't disappear one day. – Martin Jan 01 '11 at 18:32
-
As Martin rightly pointed it out, this needs a little edit, in case the link died out. – Sephy Jan 04 '11 at 22:35
-
This tutorial did helped me. This is an ultimate solution to my problem :) – Jay Mayu Feb 06 '11 at 06:59
-
Tried it on a API 2.1 device. Didn't work good. I guess maybe my font was big and caused memory issues. Or similar. I just found something that may be a fix: http://stackoverflow.com/a/5941665/129202 – Jonny Jan 22 '13 at 06:27
-
Nice one! Worked a treat. – null loop Jul 31 '13 at 14:07
-
is android support .eot, .svg and .woff font types ? – Kamal Upasena Feb 18 '15 at 16:40
-
Yeah, tutorial link is dead. Good thing you summarised it! – Matt Lyons-Wood Aug 23 '15 at 10:36
-
1A copy of the original tutorial: https://web.archive.org/web/20140115015420/http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts – Bob Sep 22 '15 at 07:58
2
Your can take look in this thread as well to set custom fonts for all the views in your activity.

Community
- 1
- 1

Chaitanya K
- 1,827
- 4
- 32
- 67
-
1As in the other answer to this question, it would be really handy if the important content of the thread was inside the question, in case the link dies one day. – StackExchange What The Heck Jan 28 '14 at 16:27