free
web stats

Android – How to Use External Fonts in Android Studio

How to Use External Fonts in Android Studio

In this post, I will show you how to use external fonts inside Android Studio. To show you how this is done I need to a new project.

First of all create an empty android project and go to activity_main.xml layout page. I’m going to add a new TextView and a new Button. Our activity_main.xml file codes here;

Now if you want to use external fonts inside the application, you first need to place these fonts inside a folder by the name of assets. By default if you look at folder directory, asset folder is not present inside this directory.

Firstly we need to create new asset folder like this.

Right click app foler–>New–>Folder–>Asset Folder

Then we need new font file. You can download these sites .ttf font file if you dont have. I have already test.ttf file and add the file inside asset folder.

https://www.1001freefonts.com/

Now paste this font file inside asset folder.

Then we are going to go MainActivity class and add these codes in here;

In this class, firstly we are define text and button then add new instance named typeface. Then set textView‘s typeFace with new font in btnChangeTextFonts‘s setOnClickListener method

Click button and show result.

You may also like...

Leave a Reply

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