# Custom Fonts on Android with Android Support Library

DevFeed: [Custom Fonts on Android with Android Support Library](<https://devfeed.tech/articles/custom-fonts-on-android-with-android-support-library-25834.md>)

Original publisher: [Read original article](<https://segunfamisa.com/posts/custom-fonts-with-android-support-library>)

Author: Segun Famisa

Published: 2017-09-04T12:00:00Z

Content type: tutorial

Language: en

Sources: [Segun Famisa](<https://devfeed.tech/sources/segun-famisa.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [fonts](<https://devfeed.tech/tags/fonts.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [library](<https://devfeed.tech/tags/library.md>)

## AI overview

This tutorial explains how to use Android Support Library 26 to declare custom fonts in XML and programmatically on devices running API 14 and later. It contrasts this approach with custom views and the Calligraphy library.

## Source excerpt

Android Oreo was officially unveiled a couple of weeks ago, and it introduces a lot of new and exciting features. If you haven't already, you should check the developers website for the list of what's new in Android O. One of the really interesting features for developers is the new way to apply fonts right there in your XML files. That's great right? Yup. Except that it works out of the box for only API 26 (Android O). In this post, we will look at how to backport this awesome feature to older versions - down to API 14 using the Support Library 26. Custom Fonts on Android - Old Ways. Previously on Android, there were limited ways to use custom fonts on Android. The following techniques are the ones I consider the most popular ways of implementing custom fonts in Android: 1. Custom Views One would typically need a custom view that extends the equivalent view where trying to apply a font to. In the custom view, one would create a Typeface and then call setTypeface (or a similar method, that, sets the typeface). One would also need to have the font file placed in the assets folder. The code in the custom view typically looks like: Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName; setTypeface(tf); 2. Calligraphy Library Thanks to some awesome developers, there is another approach to having custom fonts in your apps - and the library is called Calligraphy - https://github.com/chrisjenx/Calligraphy. The usage is fairly straightforward, and the pitfalls are clearly identified. But as with every library, it comes with the penalty of adding extra dependencies thereby increasing method count. Custom Fonts with Support Library - The New Way. Thanks to the good folk at Google and their work on Android Support Library 26 it is now possible to declare fonts in XML - something called font families, and also programmatically without the need of an extra library besides the support library (which you most likely already use in your app anyway). H