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.
Step 3 – Go to android project and right click on “app” and create a new Android Resource Directory and name it font –
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)
Step 6: Go to the strings.xml file of your app and create a string (Be sure to append \u to the unicode) –
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.
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! 🙂