Can I embed a custom font in an Android app?

I would like the application to include a custom font for rendering text, loading it, and using it with standard elements like StaticText. Is it possible?

+71
android fonts
Aug 06 '10 at 13:24
source share
3 answers

Yes you can, you cannot define it in xml layouts. You must use it dynamically every time. For example, this tutorial .

If the link is dead, here is the sum of things:

  • Get a font file, e.g. times.otf
  • Put it in the folder with your resource, in the "fonts" folder
  • Get a TextView link with something like this:

     TextView tv = (TextView) findViewById(R.id.myCustomTVFont); 
  • Take the font from the resource folder:

     Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/times.otf"); 
  • Make your TextView great:

     tv.setTypeface(tf); 
+134
Aug 6 2018-10-06
source share

You can look in this thread and also install custom fonts for all types in your activity.

+2
Aug 23 '12 at 6:17
source share

Starting with Android 8.0 (API level 26), you can use fonts in XML. See the documentation here .

0
Nov 02 '17 at 18:42 on
source share



All Articles