Android — Apply custom font family onTextView

Konstantinos Evangelidis
2 min readAug 9, 2020

Based on my experience as android developer, i know that a ‘nice’ font family makes the apps more beautiful and user friendly. Using custom font family, can change the default fonts of the application.

Using https://fonts.google.com/ you can find a huge colection.
Select any font you like and pressing download you will download a ziped file like the image below

Inside this file you will find one or more file file_name.ttf

After that in your project you have to create under res an Android Resource Directory named font. Paste the the ttf file into this foler.

Following these steps you will something like this

Lets apply a font family to TextView

Using xml code

Using this line into an element you will apply simple and easy a font family

 android:fontFamily="@font/chilanka"

So the textView i gonna looks like this

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:fontFamily="@font/chilanka"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Using kotlin code

Use this code

val fontFamily = ResourcesCompat.getFont(this, R.font.chilanka)
font_textview.typeface = fontFamily

After all these steps you will have a different style similar to this

Source code here

Feel free to leave any comment.

Thank you very much

--

--