How to Set a Custom Font for an Entire App

In some projects, you may need to use a font other than Roboto, the default font of Android. To achieve this task, you don’t need to set typeface for each view in your project one by one. There is a very simple solution provided by Calligraphy library.

First, you need to add the following dependency to your module-level “build.gradle” file:

Now, create a “fonts” folder under your project assets, and put your custom font, named as “custom_font.ttf” for instance, there. Then, in your code, initialize the library inside onCreate() of your custom Application class as follows:

As the last step, you need to override attachBaseContext() methods inside your Activity classes as shown below. Instead, you may also prefer to override this method inside an abstract base Activity and let all your concrete Activity classes extend this base Activity.

So, we addressed the issue stated in the title of this post. However, what Calligraphy can do is more than that. You can find all other use cases of Calligraphy on its GitHub page: https://github.com/chrisjenx/Calligraphy

Leave a Reply

Your email address will not be published. Required fields are marked *