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:

1. Declare a class to Override Fonts:

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

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 CustomFontApp.java that extends Application class and add the following code to it:

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:

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:

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

[adinserter block=”8″]

LEAVE A REPLY

Please enter your comment!
Please enter your name here

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

LATEST POSTS

3 Sum | Leetcode #15 | 100 Days of Code Day 10

Today we are going to solve 3 Sum - our first Medium Level Array problem from Coderefer DSA Sheet. If you are new to this...

Best Time to Buy and Sell Stock – Day 7 | 100 Days of Code

Welcome to Day 7 of 100 Days of Code where today we solve yet another most frequently asked easy array problem called - Best Time...

Contains Duplicate – Day 8 | 100 Days of Code

Welcome to Day 8 of 100 Days of Code and today we are going to solve yet another easy-level problem - Contains Duplicate as part...

Two Sum – Day 6 | 100 Days of Code

Welcome to Day 6 of 100 Days of Code where we solve the most frequently asked Easy level Array problem - Two Sum. Let us...
Exit mobile version