Tips to Use Font Awesome Icon Pack In An Android Application

blog

Dhruvil Pandya

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.

#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

Related Post

Mobile Application Development Platforms in 2022
28 Oct 2021261 Views

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 north of 5 million apps in the Google...

Android Emulators
02 Aug 2021214 Views

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 developers always look to test their app...

Android 11 App Migration
14 Jul 2021226 Views

Android 11 App Migration: Android to Android App Migration Guide

Android 11 launched last year and was released to most Android smartphones by the end of the year. Interestingly, it was one of the most awaited...