Use Font Awesome Glyph Icons With Android

Creating clean looking user interfaces in Android can often be challenging. With all the screen resolutions and screen densities that exist for Android, a lot more must be taken into consideration than iOS apps.

A nifty trick I figured out is being able to use font glyphs instead of PNG or JPEG images. When using standard images you must create an image for every density (xxhdpi, xhdpi, hdpi, mdpi) and even then it still might not look clear. When using font glyphs, the images will always look crisp because they are vector graphics.

For this example, I’m going to use Font Awesome because it is open source and there are more than 400 glyphs included.

To use Font Awesome in your Android project, start by downloading the font package and including the TTF file in your project’s assets directory. For keeping things clean, I am going to include the TTF file like the following:

assets/fonts/fontawesome.ttf

Navigate to your main.xml layout file in the res/layout directory and make sure your layout looks like the following:

In the above code we are setting the type face to use Font Awesome and then we are replacing the text in our TextView with a glyph. It is important to use the unicode value that can be found in any of the glyphs on the Font Awesome website. In this example I used the fa-users glyph icon.

You’ll notice that when we use glyph icons with Android we can set the text size to anything and it will still look crystal clear.

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.