Close

Tips to Use Font Awesome Icon Pack In An Android Application

In this tutorial, I will show you how to use the Font Awesome icon pack in an Android project. Font Awesome is a great timesaver for several reasons.

First, you don’t have to worry about different screen densities on different smartphones. If you want to use PNG files, you have to include in your package at least four different versions of every icon. Not only that, on some ultra-dense HD displays, your icons might look grainy. This is something you certainly want to avoid. With Font Awesome, however, you just have to include a single TTF file.

Font Awesome Icons

(Source)

#1 Steps to use Font Awesome in Android:

1) Create a new project

2) Create String resources in res/values/string.xml

 

#2 How to Import Font Awesome in Android:

You need Download and import the FontAwesome TrueType file into your project. You can download the FontAwesome assets from here — http://fontawesome.io/
When you download FontAwesome, you end up with an archive that includes a number of files and folders. Most of these are useful for web projects. We are only interested in fontawesome-webfont.ttf, which is located in the fonts folder.

1) Create assets folder and subdirectory fonts and add fontawesome-webfont.ttf to this folder:

In your Android project, navigate to app > src > main. The main directory should include a folder named assets. If there isn’t one, then create it. In the assets directory, create another folder, fonts, and add fontawesome-webfont.ttf to this folder.

2) Create a helper class:

Now that you’ve successfully included the FontAwesome font file in your Android project, it’s time to use it. We will be creating a helper class to make this easier. The class we are going to use is android.graphics.Typeface. The Typeface class specifies the typeface and intrinsic style of a font. This is used to specify how text appears when drawn (and measured).

Let’s start by creating the helper class. Create a new Java class and name it FontManager:

 

#3 Conclusion

In this quick tip, I showed you how to use the FontAwesome icon set in an Android project. FontAwesome is widely known, very rich, and free. The result is sharp and crisp icons, even on high resolution displays. As an added bonus, changing an icon’s size or color is as simple as changing an XML attribute.

You can find the complete code here:

Full Source Code

Top-5 Best Mobile Application Development Platform in 2022

It is not an exaggeration to say that Android is the most popular mobile OS with 85% market share and Read more

Android & iOS Mobile App Developer latest required Skills in 2022

With respect to current industry standards, it has become vital for developers to have knowledge of multiple platforms. There are Read more

What are Android Emulators and How to Setup an Android Emulator?

There are a variety of reasons why you would want to run an Android emulator on your PC. Mobile app Read more

Dhruvil is a marketer for Nimblechapps, an app development solutions company joining December 2014, based out of Sydney, Australia. He has worked briefly as a Branding and Digital Marketing Manager before moving to Australia. At Nimblechapps, he worked on Social Media Marketing, Branding, Email Marketing and Blogging. Dhruvil studies Business at University of Western Sydney, and also handles Operations for the company in Australia.