It’s easy to add custom fonts in the Android Studio project. First, visit the Google Fonts website. It is a library of 1504 open-source font families and beautiful icons. For this article, I’m using Poppins font. Open the fonts page and click on the “Download family” button.
You will get a zip file with all the font styles. Extract it. Next, open Android Studio, right-click on the res folder, and select New > Android Resource Directory.
From the “Resource type” menu, select font and click on the OK button.
Now, font folder is added to the res directory. Open the Poppins folder (that you extracted). You will find .ttf files.
Copy the .ttf files and paste them into our new font folder (right-click on the folder and select paste). Now, expand the folder. You may see errors.
This is because the name of the resources should be written in small characters. Also, we should only use the underscore to separate the words. To change their name, right-click on the font and select Refactor > Rename.
Use small letters and add the underscore between the words.
Now, you have successfully added the fonts to your project. Let’s see how to use them in the code.
If you are using XML:
You can use android:fontFamily tag to add fonts:
<TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SemicolonSpace" android:fontFamily="@font/poppins_bold" />
If you are using Jetpack Compose:
There are different ways to use custom fonts. Follow this article on Jetpack Compose Themes.
This is how you add custom fonts in Android Studio. If you have any doubts, comment below.