How to add Custom Fonts in Android
Last Updated :
23 Apr, 2024
Google Fonts provide a wide variety of fonts that can be used to style the text in Android Studio. Appropriate fonts do not just enhance the user interface but they also signify and emphasize the purpose of the text. There are majorly three methods to add custom fonts to text in Android Studio. The first two methods involve the use of the Typeface class while the last method is quite direct and easy. Follow the entire article to explore all the methods.
Method 1
In this method, we'll first download the font's ttf file from the internet and then use them as an asset or a resource to set the Typeface. You may find the downloadable fonts here. Here Dancing Script font is used. Once you download the fonts of your choice, unzip the folder and copy the font file. By creating a new Android resource directory:
Step 1: In the project's resource folder, create a new Android Resource Directory of Resource type: font and paste this 'ttf' file here. Note that while pasting it, keep in mind that a resource file's name can consist of lower-case letters and underscores only, so refactor the file accordingly. 
Step 2: Create the layout in the XML files.
Step 3: Now in the MainActivity(necessarily the Activity corresponding to the layout file where the TextView to be customised lies), set the typeface for that TextView.Â
MainActivity.java
package com.example.android.customfonts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textview);
Typeface typeface = ResourcesCompat.getFont(this, R.font.dancing_script_bold);
textView.setTypeface(typeface);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GeeksforGeeks"
android:textColor="#006600"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output:

By Creating a New Asset Folder
Step 1: Create a new asset folder(app/New/Folder/Asset folder) in Android Studio and paste the 'ttf' file of the font here. The picture on the left shows how to add the assets folder to the project whereas the picture on the right shows the added 'ttf' file to it. 
Step 2: While we keep the XML layout to be same as earlier, the Java code of the MainActivity is modified this way.Â
MainActivity.java
package com.example.android.customfonts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
import com.example.android.customfonts.R;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textview);
Typeface typeface = Typeface.createFromAsset(getAssets() , "macondo_swash_caps_regular.ttf");
textView.setTypeface(typeface);
}
}
Output:

Method 2
In this method we'll create a separate java class dedicated to a particular font and use this class instead of the conventional TextView tag in the XML file.
Step 1: Download the font of your choice and use either of the above two approaches to store it in the project. I have pasted my file in the assets folder.
Step 2: Create a new Java file in the package. Preferably name it according to the font that you want to implement. Here we have created a file named CalligraffittiRegular.
Step 3: Extend the following class in this Java file:
androidx.appcompat.widget.AppCompatTextView
Step 4: Complete the Java code by adding the required constructors.
Step 5: Create a method in the class wherein the typeface for the font is set.
Step 6: Call this method in each constructor. Refer to the following code for a better understanding.Â
CalligraffittiRegular.java
package com.example.android.customfonts;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
public class CalligraffittiRegular extends
androidx.appcompat.widget.AppCompatTextView {
public CalligraffittiRegular(Context context)
{
super(context);
initTypeface(context);
}
public CalligraffittiRegular(Context context,
AttributeSet attrs)
{
super(context, attrs);
initTypeface(context);
}
public CalligraffittiRegular(Context context,
AttributeSet attrs,
int defStyleAttr)
{
super(context, attrs, defStyleAttr);
initTypeface(context);
}
private void initTypeface(Context context)
{
Typeface tf = Typeface.createFromAsset(
context.getAssets(),
"calligraffitti_regular.ttf");
this.setTypeface(tf);
}
}
Step 7: Now in your XML layout file, use this font class instead of the conventional TextView tag.Â
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.customfonts.CalligraffittiRegular
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GeeksforGeeks"
android:textColor="#006600"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.616"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.462"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Output:

Method 3
With Android 8.0 (API Level 26) a simpler method was introduced for using fonts as a resource in Android Studio. The android:fontFamily attribute of the TextView class is used to specify the font.
Step 1: Go to the XML file and go to the Design view.
Step 2: Click the TextView you want to change the font of.
Step 3: In the search bar, search for fontFamily. 
Step 4: In the dropdown menu, you can check out the fonts available. In case you want to explore more, scroll down and click 'More Fonts...'.
Step 5: A dialog box pops up. Choose a font of your choice, choose the style you like in the preview, and click OK.
Step 6: This would create a downloadable font and add it automatically to your project.
The following files automatically get added to your project: 
Step 7: Now the XML file will be look like:Â
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/aref_ruqaa"
android:text="GeeksforGeeks"
android:textColor="#006600"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output: 
Similar Reads
Android Architecture Android architecture contains a different number of components to support any Android device's needs. Android software contains an open-source Linux Kernel having a collection of a number of C/C++ libraries which are exposed through application framework services. Among all the components Linux Kern
5 min read
Android Tutorial In this Android Tutorial, we cover both basic and advanced concepts. So whether you are a fresher (graduate) or an experienced candidate with several years of Android Development experience, you can follow this Android tutorial to kick-start your journey in Android app development. Our Android Tutor
15+ min read
Activity Lifecycle in Android with Demo App In Android, an activity is referred to as one screen in an application. It is very similar to a single window of any desktop application. An Android app consists of one or more screens or activities. Each activity goes through various stages or a lifecycle and is managed by activity stacks. So when
9 min read
Introduction to Android Development Android operating system is the largest installed base among various mobile platforms across the globe. Hundreds of millions of mobile devices are powered by Android in more than 190 countries of the world. It conquered around 71% of the global market share by the end of 2021, and this trend is grow
5 min read
Top 50 Android Interview Questions and Answers - SDE I to SDE III A Linux-based open-source OS, Android was created by Andy Rubin and became one of the most popular smartphone operating systems. With 71 percent of the market share worldwide, Android is on top. Because it is on top in the smartphone OS, Android development is always in demand.If you are seeking a j
15+ min read
Android UI Layouts Layouts in Android define the user interface and hold UI controls or widgets that appear on the screen of an application. Every Android application consists of View and ViewGroup elements. Since an application contains multiple activitiesâeach representing a separate screenâevery activity has multip
5 min read
Top 50 Flutter Interview Questions and Answers for 2025 Flutter is an open-source, cross-platform application development framework. It was developed by Google in 2017. It is used to build applications for Android, iOS, Linux, Mac, Windows, and the web. Flutter uses the Dart programming language. It provides a simple, powerful, efficient, and easy-to-und
15+ min read
Components of an Android Application There are some necessary building blocks that an Android application consists of. These loosely coupled components are bound by the application manifest file which contains the description of each component and how they interact. The manifest file also contains the appâs metadata, its hardware confi
3 min read
Android Studio Tutorial It is stated that "If you give me six hours to chop down a tree then I will spend the first four hours in sharpening the axe". So in the Android Development World if we consider Android Development as the tree then Android Studio should be the axe. Yes, if you are starting Android Development then y
9 min read
MVVM (Model View ViewModel) Architecture Pattern in Android Developers always prefer clean and structured code for projects. Organizing the codes according to a design pattern helps in the maintenance of the software. By having knowledge of all crucial logic parts of the android application, it is easier to add and remove app features. Further, design patter
8 min read