How to add a custom font to an Android Studio project

Oscar de la Hera Gomez
Three flowers that represent Kotlin, Android and Android Studio side by side. Beneath them sits the text “Add Custom Font.”

A step by step guide on adding custom typography to an Android Studio project that uses Kotlin and Jetpack Compose.

The following tutorial walks you through how to add Roboto to an Android Studio project. Roboto was acquired using Google Fonts.

We recommend that you clone our Open Source Kotlin Starter Project, checking out the main branch and carrying out the steps below. The changes can be found on the tutorial/basics/font.

git clone git@github.com:delasign/kotlin-android-starter-project.git

Step One: Create the Fonts Folder

A screenshot of Android Studio showing you how to create a fonts folder.

With Android selected in the Project Inspector (top left), right click on the res folder and create a new Font Folder (new > Android Folder > Font Folder).

A screenshot of Android Studio showing the pop up that appears when you create a font folder. Press finish on the bottom right.

In the pop up that appears, select Finish.

Step Two: Add the Fonts

A screenshot of the pop up that appears in Android Studio after you drag and drop fonts. Click Refactor found on the bottom right of the pop up.

Drag and drop the fonts into the new fonts folder.

In the pop up that appears, click Refactor.

Step Three: Update the Font Names

A screenshot of Android Studio showing the fonts before being renamed, along with the menu that allows you to rename them.

Rename the fonts to only allow for:

  • lowercase characters
  • underscores

This implies no capital letters, spaces or -.

A screenshot of Android Studio showing the fonts after being renamed.

The fonts after being renamed.

Step Four: Create the Font Resource File

A screenshot of Android Studio showing you how to create a fonts resource file.

Right click on the font folder and create a Font Resource File (New > Font Resource File).

A screenshot of the pop up that appears when you try to create a Font resource file. Add a file name in the "file name" input and click the OK button on the bottom right.

Name the Font Resource File after your Typeface and click OK.

Step Five: Add the Fonts to the XML

A screenshot of Android Studio showing how we populated the fonts resource file with all the robots fonts.

Add the fonts to the fonts.xml through code similar to the one below.

Please note that the fontStyle can only be normal or italic.

Step Six: Create the Font Family

A screenshot of Android Studio showing the Type.kt file, with the Robot FontFamily as a Kotlin val.

In the Type.kt file found in the ui.theme folder, create the FontFamily using code similar to the one below.

If you are using our open source project, please note that the theme folder is now found under the styleguide folder in our main branch as it forms part of the Styleguide.

Looking to apply the custom font to Text ?

Follow our guide linked below to learn how to use a custom typeface with Kotlin and Jetpack Compose.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details