How to use a custom font for a TextView? [SOLVED] – Android Studio

First of all make sure that you have an assets folder in your project with this location. Then create a folder named ‘Fonts’ inside it and paste the font file there. So that the font file has a location like this: app/src/main/assets/fonts/font.ttf

You can download the font files which are in .ttf format from Google Fonts or any other website.

Then add the following code to the activity.
First , get the reference of the text view in the code. Its syntax is given below −

TextView tx = (TextView)findViewById(;

The next thing you need to do is to call static method of Typeface class createFromAsset() to get your custom font from assets. Its syntax is given below −

Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/font name.ttf");

The last thing you need to do is to set this custom font object to your TextView Typeface property. You need to call setTypeface() method to do that. Its syntax is given below −


So your complete code looks like this:

TextView tx = (TextView)findViewById(;
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/font name.ttf");


PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in computational material science. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT and Machine Learning related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]

One thought on “How to use a custom font for a TextView? [SOLVED] – Android Studio

  1. hello your code work in android studio. this code is only one font so i have many more font.
    i have create one button and change to font many type. how can do this please help me. thanks for code.

Leave a Reply

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