Font Awesome is very popular icon toolkit used across many websites. It has both free and pro collection of icons, but you can find most the icons in free collection itself. Each icon will represented by unicode (). We use this unicode to display the icon in TextView. As it’s a normal TextView, all the text styling attributes (color, size, paddings etc.,) can be applied.
For an example if you want to display android Robot logo, you can use unicode as TextView value.
In order to use the font awesome icon collection, you have to add the font awesome font files to your assets directly and apply the appropriate fontFace on to TextView which is simpler task. But we want the icons to be displayed in other widgets also like in Buttons, Menus, Bottom Navigation and Navigation Drawer etc,. Displaying icon in non-textual views takes some effort. So I have written a library by incorporating all the necessary methods to render the icons in multiple widgets.
To get started, include the fontawesome in your build.gradle and sync your project.
The easiest way to display the font icon is, use the FontTextView text by setting the appropriate icon name as text value. This widget extends from AppCompatTextView, so all the text view attributes applies to this widget.
Using the icon in xml layout is easy, but if you want to use the icon for other widget like button or menu, you can use the FontDrawable element to apply the icon.
For an example, if you want to use the font awesome icon to Floating Action Button, you can use the FontDrawable as shown below.
You can also use the font icons in the widgets that uses menu file to render the items like Toolbar icons, Bottom Navigation, Navigation Drawer etc., To render the icon in menus, you can use the FontDrawable to set the icons, but it needs few hacks through java code.
The below example shows rending the font awesome icons in Navigation Drawer menu. Full example can be found here.
I hope you like this library. If you have any suggestions, please let me know in the comment section below.
Happy Coding 🙂
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: [email protected]
wow..this is so nice.definitely need this
Thanks:)
Great, i was looking for such a tutorial
Cheers!
Hai Ravi.. Is there really a difference between fontawesome icons and native android icons?
Which icon set you are referring native android icons to?
maybe his refering to native android vector drawable in android studio
exactly
I got your point. These two has different collection of icon sets. Not all the icons are available in android icon set. Again it depends on your requirement. I recently worked on an app that has few hundreds of icons to be displayed from which user can select one. I choose font awesome as it has great collection.
Also in this library, I used the font files ttf directly instead of svgs because of the time crunch.
Great ! This time you have explain your own lib.(Ha ha ha)
You always share a very good knowledge. 🙂
Thank you again your great contribution. I have one request, if possible
can you share one tutorial for “mvvm” bassed on new architecture component ?
Thanks Rahul. I have MVVM in my queue since 6months but couldn’t complete the article 🙁 I have to post a code sample at least on my git.
Pleeeeeease write tutorials with flutter, I love your tutorials 😀
Great library!
How i can use it in a Bottom Navigation?
I have given an example on how to render the icons in menu file. You can use the same to render the bottom navigation.
This is awesome library.
Ravi could you please make a tutorial for streaming audio player with recording option just like exoplayer, may be custom EXOPlayer.
Thanks
Great work
Can you please make tutorial MVC, MVP, MVVM bro?
Preparing one article on Dagger2 and MVVM. It takes 2-3 weeks to prepare.
Greatest blog on the internet for Android development. Has everything you need to get started.
Thanks Ibrahim 🙂
Hey there bro, i wanna learn backend services.Which language would be suitable to learn backend?
To get started learn PHP. Then move on to RoR, Node js or Django.
How about learning JSP? Is there any advantages of learning PHP over JSP?
Hi Ravi,
I am the very old follower of your website and great work, (From basic to till I mostly learn from you,”Specially You introduced me with parse server and applications on it”), Now I am here to requesting you to write a post about Android Equalizer (Because there is no example / tutorial or much detail on the internet for mediator like me). Hope you will consider my request.
Teach us how to make a library for Android. 🙂
Hi @Ravi Tamada:disqus ,
IMHO, your post is a bit confused since it seems there are two examples when there is only an example really.
If you allow a suggestion in order to improve this post, I would like to give it you with pleasure.
Best regards.
lol
Example 1: Setting fa icon value directly in xml
Example 2: Programatically displaying icon in Android views like buttons, fab.
Example 3: Using the icons in widgets that uses menu files to render icons.
Let me know if this is still not clear.
ERROR: Plugin with id ‘com.android.library’ not found
I opened your project but AS showed the above message.
Any idea to solve this issue?
Android Studio 3.4.1
Build #AI-183.6156.11.34.5522156, built on May 1, 2019
JRE: 1.8.0_152-release-1343-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Hi Sir , Please create one more Post Auto verify moble number using Incoming call same as Ola App Login Screen
Thanks for sharing with us……
Hi,
I’m having trouble with this. My icons are not rendering properly. Most of them are showing up as a rectangular box.
I added the three java files into a folder: “com.mycompany.appname.fontawesome”
Then I changed package name in the files to match folder path
I added the three .ttf files to the assets folder
I added the strings to strings.xml
I added the attribs file to the “res/values” folder
I added this to build.gradle: implementation ‘info.androidhive:fontawesome:0.0.5’
Here is my textview:
What am I missing here?
thanks in advance!
You’re an asshole for deleting my question you fucking prick. Your documentation sucks by the way.
This fucking prick deletes legitimate questions instead of trying to help people out. You’re a fucking asshole and I hope you grow balls in your throat while sleeping tonight, fuckface.
I bet you suck your own dick don’t you. Notice the lack of anything but positive messages on here. Where are the actual legitimate questions people might have on your library, fuckface?
1. download code
2. file > new > import module in Android Studio
3. select the font awesome subfolder and finish the import wizard
4. if not using artifactory, delete or comment that code in build.gradle
5. make sure: targetSdkVersion and compileSdkVersion = 28
6. put the .ttf files into your assets folder
7. try to build project. If it don’t work at that point it should be something minimal. Try posting on stackoverflow because it looks like he has abandoned replying on this discussion…
*You can also run the downloaded project and dissect it to see how it works.
**Do not download individual files from github. Download the whole zip file
***If icons don’t render properly, try putting fresh copies of the .ttf files into your assets folder
Hope this helps!
…and I would like to humbly thank the author of this code for the work he did!
Thanks Boogie:)
Hi @Ravi Tamada:disqus how can I use my icons with the library. I have a .ttff file how can I integrate it ?
Is it a web font?
yeah it’s a webfont
Update: It’s not a web font but a font-awesome.ttf file. How can I use it in my android app ?
Fucking thank you, been watching a lot of tutorials that didn’t work for me. This is simple and very efficient.
BTW, I’m working on a very simple project that requires backend, do you think PHP is the easiest way to go for such a simple project? I already know that language but unsure if it’s good enough.
You are welcome 🙂
Yes PHP is easiest way to get started but once you got enough knowledge move onto RoR or Django.
Waw, thank ou
You are welcome 🙂
Hello Ravi
Please make tutorial on viewmodel with navigational drawer project as new technology
Thanks
Hi, you can help me, in my layout have a message “Error mapping font file fa-solid-900.ttf ” how I can fix it
How can I use Font Awesome with BottomNavigationView pleaaase
Read 2.3 in the article. It applies to Bottom Navigation as well as it uses menus to render icons.
AndroidHive
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = “//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.9”;
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, ‘facebook-jssdk’));
copyright © 2017 Droid5 Informatics Pvt Ltd
www.droid5.com