How to Change Typeface of TextView in Android?
A typeface is a particular design for alphabets that separates it from other typefaces in terms of style, size, and weight variations. In general, there are a lot of local typefaces available on your device or software for use. However, many more typefaces are available on the Internet that can be downloaded and used for respective works.
Similarly, such typefaces can be introduced for displaying the text inside the TextView. So in this article, we will show you how you could use a download typeface and apply it to the text inside the TextView of your Android application.
Step by Step Implementation
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. Add a TextView in the layout file.
Step 3: Download and store the desired font in the assets folder
We download a font from here. However, you can download a font of your choice. Now, just copy the downloaded font file and paste it into the assets folder. In case, you have no clue about the assets folder, or if it is missing from your folders, create a new assets folder by following this article on Assets Folder in Android Studio.
Step 4: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
You can see that the typeface is applied to the text in the TextView.