Make your texts prettier in Android

Kako Botasso
3 min readMar 11, 2017

--

I was working on a project, and had to use a font different from default and I wasted many time looking for how do that. So I decided to write this article to help people with the same problem as I. If you prefer, you can find this article in Portuguese just by clicking here.

Let's start creating a new project in Android Studio with an Empty Activity in that. Now we have to go to app/src/main in project folder, and then, we will create another folder called assets.

Assets folder created

After made this, we can add the font we'll use inside it. For this article, I'll use Lobster font, and it can be downloaded on Google Fonts. After finish the download, unzip it, and move Lobster_Regular.ttf file to our assets folder.

When we put our font inside the right folder, Android Studio already recognizes that it as a resource that will be used in the project.

Android Studio recognize as a resource

After the font is in project, let's add an id to the TextView that we want to let prettier.

Layout of MainActivity

If we run the project right now, we'll see nothing different. We'll see a "Hello World!" with the same default font.

Still the same default font :(

We want to apply the new font in our text, so let's make some changes in our Activity. We'll put the TextView inside a variable, and will create a Typeface passing our assets and the font name as a String. So, we have to apply the created Typeface to TextView.

If we ran our project again, after all changes, we'll see the TextView with the new font.

That's so pretty *-*

This way to use custom fonts is very simple and very easy, but if we want to use custom fonts in the entire project, we'll have to copy the code in many places and that's not good. We can solve this in a very simple way, but we'll see this in other article ;D

Hope this article have helped and hope see you soon. If you have any doubt, don’t be afraid to ask in the comments. If you liked it, recommend and share :D

--

--