Adding Font Awesome to your Android app

Hello Everyone!

Icons are an integral part of the User Interface of every application and for the web applications I like to use the Font Awesome icon library. So when I switched to android I wanted something similar for my android apps too. I tried using the Material icons library but that didn’t work out for some reason. πŸ˜› So, today I’ll be sharing how to use font awesome icons in your android app.

Font awesome is super lightweight and you can easily customize the color and size of the icons like text and the they have a large variety of icons. So let’s get started.. πŸ˜€

I am using Windows 10 and Android Studio 3.2.1 here.

Step 1 – Download the font awesome zip file from Font Awesome.

Step 2 – Locate the .tff files in the webfonts folder inside the zip.

Capture

Step 3 – Go to android project and right click on “app” and create a new Android Resource Directory and name it font

Creating Android Resource Library

Creating Android Resource Library

This should create a folder named font inside res folder of your app.

Step 4 – Copy the font awesome .tff file (whichever you need out the three) inside the font folder. (Make sure that the file name only contains a-z 0.9 and underscore)

Android Studio file structure

Step 5: Search for the icon you want to use at – https://fontawesome.com/icons and note down the unicode. For example – the unicode for bolt icon is f0e7.

Font awesome bolt icon unicode

Step 6: Go to the strings.xml file of your app and create a string (Be sure to append \u to the unicode) –

\uf0e7

Step 7: To display the icon create a TextView and set app:fontFamily as shown below –

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/fa_energy"
    android:textSize="30dp"
    android:textColor="#000"
    app:fontFamily="@font/fa_solid"/>

and we are done…

You can use as many icons as you like in a similar way.

Android app with font awesome icon screenshot

Here is a link to the GitHub repository for this code – Font Awesome android app – GitHub repository

If you enjoyed using Font Awesome, go ahead and check out their website. They have recently launched the PRO version and it’s totally worth it. πŸ™‚

I hope you found this post helpful. Please feel free to comment down your thoughts below also let me know if you faced any difficulties and I will try to respond.

Have a nice day! πŸ™‚

Advertisements

One thought on “Adding Font Awesome to your Android app

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s