Thursday, June 1, 2023
HomeAndroidAndroid Custom Font For Entire Application using Android Studio

Android Custom Font For Entire Application using Android Studio


In this Android custom font article, we will look at how to apply custom font for the entire Application.

Here I am taking the project of my previous article on FirebaseUI and cloning it to apply custom font to that application. The entire code for this tutorial is made available as a separate Github project. You can clone/download.from the following link:github source code link for android custom font sample application

1. Declare a class to Override Fonts:

We declare a class to override the fonts. Here I’ve named it as

package com.coderefer.firebasedatabaseexample.util;
import android.content.Context;
import java.lang.reflect.Field;
* Created by vamsi on 06-05-2017 for Android custom font article
public class FontsOverride {
public static void setDefaultFont(Context context,
String staticTypefaceFieldName, String fontAssetName) {
final Typeface regular = Typeface.createFromAsset(context.getAssets(),
replaceFont(staticTypefaceFieldName, regular);
protected static void replaceFont(String staticTypefaceFieldName,
final Typeface newTypeface) {
try {
final Field staticField = Typeface.class
staticField.set(null, newTypeface);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {

Here I’ve declared the above class as final so that no other subclasses can be created for it so that we are restricting the concept of inheritance for this class.

[adinserter block=”8″]

2. Placing the required android custom font in our Application:

The font I am going to use is Raleway.ttf which is an open source font which can be acquired at the following link.

Create an assets folder by changing our android perspective to project and navigating to src > main and right click on main and select new > Folder > Assets Folder

Now create a sub folder in assets folder named fonts and place Raleway.ttf in fonts folder.

Now the total directory for the fonts folder will be src > main > assets > fonts > Raleway.ttf

[widget id=”text-3″]

3. Declare /Modify Application Subclass:

Android Application is the base class in Android that maintains Global Application State. We can write a subclass extending Application class and declare it in our AndroidManifest.xml‘s <application> tag. Android os will initialize the Application class or its subclass before any other classes when the process for your application/package is created. For more on Android Application class, you can visit the following link.

Here I am creating a class named that extends Application class and add the following code to it:

package com.coderefer.firebasedatabaseexample;
import com.coderefer.firebasedatabaseexample.util.FontsOverride;
* Created by vamsi on 06-05-2017 for android custom font article
public class CustomFontApp extends Application {
public void onCreate() {
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/raleway.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/raleway.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/raleway.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/raleway.ttf");

If your app already contains a subclass that extends application, then modify that class by adding the following lines of code to it.

[adinserter block=”8″]

4. Declare the application tag in Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

5. Apply typeface to styles.xml:

Now we will add the following line to our styles.xml so that the typeface will be applicable to our entire application.

<item name="android:typeface">monospace</item>

Now my styles.xml will look like:

<resources> <!– Base application theme for Android Custom Font –>
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> <!– Customize your theme here. –>
<item name="android:typeface">monospace</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style> <!–Defining colors for TextInputLayout's EditText–>
<style name="TextLabel" parent="TextAppearance.AppCompat"> <!– Hint color and label color in FALSE state –>
<item name="android:textColorHint">#9575cd</item>
<item name="android:textSize">20sp
</item> <!– Label color in TRUE state and bar color FALSE and TRUE State –>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlNormal">#9575cd</item>
<item name="colorControlActivated">@color/colorAccent</item>

view raw


hosted with ❤ by GitHub

Now run the app to see that the Android custom font is applied to the entire application!

[adinserter block=”8″]


Please enter your comment!
Please enter your name here

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


SOLID Principles in Android with Kotlin Examples

Recently I had an interview experience where I went blank when the interviewer posed an Interesting Question - Explain SOLID Principles and how they are...

Linked List Insertion – Linked List Tutorial Series #2

Linked List Insertion, unlike array or list insertion, is not pretty straight forward. In this article, we will discuss about Singly Linked List insertion. Usually...

Linked List Series #1 – Introduction – Creating a Linked list

Linked List, like arrays, is an example of Linear data structure. While linked lists are not a popular day to day data structures, they have...

Building a Multi Module App in Android | Modularization in Android #1

Recently, I was in requirement for developing a Multi Module app in Android and I was going through this great lecture on it. This article...

Follow us


Most Popular