B4A Library FontAwesome

Discussion in 'Additional libraries, classes and official updates' started by NJDude, May 22, 2015.

  1. NJDude

    NJDude Expert Licensed User

    This library will allow you to use FontAwesome on any view that supports Typeface (except Spinner).


    1- B4A 4.x.

    2- Copy the FontAwesome.xml and FontAwesome.jar to your additional libraries directory.

    'Initialize the library.
    Private FA As FontAwesome


    'Add the FontAwesome typeface to your view.
    Label1.Typeface = FA.FontAwesomeTypeface

    'Select the icon you want to display.
    Label1.Text = FA.GetFontAwesomeIconByName("fa-android") & "  Some title label  " & FA.GetFontAwesomeIconByNumber(0xf15d)
    That's it!!


    * If an icon isn't defined the library will show a "?" or a blank-square (get all the defined icons by name and their numbers from the Cheat Sheet)



    Attached Files:

    Last edited: Nov 21, 2015
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Simple and awesome!
    johndb, Cableguy and NJDude like this.
  3. johndb

    johndb Active Member Licensed User

    Very useful library! Thank you for this NJDude!

  4. ivan.tellez

    ivan.tellez Active Member Licensed User

    I dont see the real advantage of having a library, its actually more code.

    'Initialize the Typeface.
    Dim myFont As Typeface
    myFont = 

    'Add the FontAwesome typeface to your view.
    Label1.Typeface = TheTypeFace

    'Select the icon you want to display
    Label1.Text = Chr(61481)
  5. thedesolatesoul

    thedesolatesoul Expert Licensed User

    I'll list some of the advantages:
    - The font itself is embedded in the library, so the extra step of adding (and later removing) it to your assets is not required. (quite handy when quick prototyping).
    - You can mention font charachter by their name to make the code more meaningful and easier to remember and identify.
    - The library has another convenience method called SetFontAwesomeTypefaceByTag, this allows you to recursively set all views to this typeface based on a tag (or even a null tag will set all items to that typeface).

    Arguably it is only one more line of code due to FA.Initialize which is unavoidable. But in the longer sense i feel its more optimized if you only load the typeface once.
    For e.g. the above 4 lines you posted are equivalent to these 4 lines:
    Private FA As FontAwesome
       Label1.Typeface = FA.FontAwesomeTypeface
       Label1.Text = FA.GetFontAwesomeIconByNumber(
    You could argue that your above code can be further reduced by 2 lines, but assigning the font multiple times will require multiple disk accesses if you do that kind of code reduction.
    I'm sure you will see the benefit both in number of code lines and loading the typeface when you have much more views to deal with.
  6. NJDude

    NJDude Expert Licensed User

    Note that there's also a method to add FontAwesome to all the views in one shot:
  7. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Can it be uset in Activity.AddMenuItem ?

    I try with:

    Activity.AddMenuItem(FA.GetFontAwesomeIconByName("fa-money")&" Tenencia","mTenencia")

    and did not work

  8. NJDude

    NJDude Expert Licensed User

    It doesn't work because the menu doesn't support Typeface.
    DonManfred likes this.
  9. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Thanks and how can I adda android icons to the menu items? whwre can I found it?
  10. DonManfred

    DonManfred Expert Licensed User

  11. Dave O

    Dave O Active Member Licensed User

    If you're using the PopupMenu component of the stdActionBarHelper library (which is how I add multiple menus to my apps), you can add icons like this:
    Dim overflowMenu As PopupMenu
    "overflowMenu", overflowButton)
    Dim bmd As BitmapDrawable
    LoadBitmap(File.DirAssets, "share32.png"))
    "Share as HTML", bmd)
  12. mat2175

    mat2175 Member Licensed User

    Hi, Is there a way to change the colour of the Typeface
  13. johndb

    johndb Active Member Licensed User

    Change the TextColor property of the FontAwesome's host control:

    Private FA As FontAwesome
    Label1.Typeface = FA.FontAwesomeTypeface
    Label1.Text = FA.GetFontAwesomeIconByNumber(
    Label1.TextColor = 
    NJDude and thedesolatesoul like this.
  14. jotaele

    jotaele Member Licensed User

    Is posible to use two fonts in a Label? I think that no but...

    When you use FA to put an icon, the rest of the font of the label changes and it's different to the font of the app.

  15. thedesolatesoul

    thedesolatesoul Expert Licensed User

    NJDude likes this.
  16. Inman

    Inman Well-Known Member Licensed User

    This is awesome. You can display icons near text, without worrying about adding an imageview and then positioning, padding and aligning it correctly with the text.

    Thanks man.
  17. jotaele

    jotaele Member Licensed User

    Thanks. I will use this workarround.

    btnMapaIcon.Typeface = FA.FontAwesomeTypeface
    btnMapaIcon.Color = Colors.RGB(62, 99, 143)
    btnMapa.Color = Colors.RGB(62, 99, 143)
    btnMapaIcon.TextSize = 24
    btnMapa.TextSize = 16
    btnMapaIcon.TextColor = Colors.White
    btnMapa.TextColor = Colors.White
    btnMapaIcon.Text = FA.GetFontAwesomeIconByName("fa-globe")
    btnMapa.Text = "Mapa"
    Activity.AddView(btnMapa, 30dip, 70dip, 100%x - 60dip, 70dip)
    Activity.AddView(btnMapaIcon, 30dip, 70dip, 60dip, 70dip)
  18. jotaele

    jotaele Member Licensed User

    It could be interesting to put a generic method to change the font for another symbolic font, even the method FA.GetFontAwesomeIconByName("fa-XXX") don't work.

    It would be amazing.

    It's only a wish-suggestion. :)

    Another wish could be to set the typeface that the generic font (not the font of the symbols) to get the Roboto font, for example.

  19. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    Hello Guys,

    I quite enjoy this library but find frustrating many things, for example: is in Hex, No Grouping, do not know if they are all continuous, bla bla bla... of course non are library specific problem.

    so i made a file that help me with that, and wanted to share.

    Attached Files:

    Jaames and johndb like this.
  20. Jaames

    Jaames Active Member Licensed User

    And example Icons of all fonts, their names and hex values in listview (copied from the cheatsheet).

    Attached Files:

    Mashiane and koaunglay like this.