How to Implement Downloadable fonts for Android

In today’s application we must have seen types for fonts for text view or edit text view. So today we are going to learn how to implement this type of fonts ie downloadable fonts in your application. You must be thinking what if we use ttf extension file for fonts. There is no problem in using ttf files but it will increase your app size. So if you want to shrink you application size then this is the best way to add fonts to your application.

Adding Font to Application

  • Place text view in your layout xml file under properties find fontFamily from Attribute tab. Under dropdown menu select More fonts. See the below image                                                                                       more android font
  • Now select the type of font you want to use. Don’t forget to check “Create Downloadable Font”. Then click on ok.                                                                                                                                                                   select android font
  • After hitting ok 3 files will be generated i.e under res ->fonts, and other two in res->values.
  • First file will consist on following code.

     
  • Other two files will be font_certs.xml and preloaded-fonts.xml.
  • The font_certs.xml will consist of following code.

     
  • The preloaded-fonts.xml will consist of following code.

     
  • Make sure that below code is added in AndroidManifest.xml. Android studio will do it automatically.

     
  • After adding above line AndroidManifest.xml will look like this.

     
  • By following this steps the font will be applied to specific text view.
  • In case you want to apply this font to whole application then add the below code in style.xml.

     

    android font user interface

That’s it guys your font will be applied to your android application. If you have any query then please do comment down below and I will be happy to help you. Thank you. 🙂 .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.