Android Question FontAwesome

achapman

Member
Licensed User
Longtime User
Hi everyone, I'm loving the new FontAwesome and Material font support in the IDE :)

A few quick questions:

1) In the B4J Tutorial, it suggests you can click an icon and then paste in the IDE to get something like: Chr(0xF17B)

However in B4A, when I paste, that doesn't work. How do I get the CHR code reference in B4A?

2) When creating a button in code (not in the designer), how do I set the Typeface to "FontAwesome"? I'm trying to do something like:

B4X:
    Dim MyTypeFace As Typeface
    MyTypeFace.LoadFromAssets("FontAwesome")
  
    Dim Btn As Button
    Btn.Initialize("MyButton_Clicked")
    Btn.Typeface = MyTypeFace
    Btn.Text = Chr(0xF17B)

However the Typeface cannot be loaded, and the IDE gives no option for Typeface.FontAwesome or similar.

Thanks in advance!
Andrew.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
However in B4A, when I paste, that doesn't work. How do I get the CHR code reference in B4A?
1. Make sure to open the icon picker from the code editor. Last item in the context menu:

SS-2016-12-21_08.01.55.png


2. Add an invisible label named lblFontAwesome with the designer and set its font to FontAwesome.
B4X:
Btn.Typeface = lblFontAwesome.Typeface
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
@Erel , for creating views in code that use FA or Material Icons font, it would be great to be able to do this using the OP's syntax (that is, without the workaround you described above). Is that planned?

Thanks!
 
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
What if i don't use LoadLayout?, i generate my layout programmatically but i cannot set the typeface to FontAwesome on the typeface list,

i used your workaround:
2. Add an invisible label named lblFontAwesome with the designer and set its font to FontAwesome.

An error ask me to initialize the Label(as i used a label) because im not using the Layout

B4X:
fontAwLbl.Initialize("faw")

Then i set the typeface to fontAwLbl typeface

B4X:
lv1.SingleLineLayout.Label.Typeface=fontAwLbl.Typeface

and used the char i want:

B4X:
lv1.AddSingleLine2(Chr(0xF0E7)&" 9 Reglas de Superviviencia", pageList.Get(0))

But its not working, i can only see Block and my text

How do i set the required font in a CODING way?

i know i can use external files or libraries, but b4a already has it, i want to do natively
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How do i set the required font in a CODING way?
Using the CSBuilder

Something like this

B4X:
Dim cs As CSBuilder
'Using the same builder multiple times. Note that it is initialized each time.
'Note that we vertically align the material icon character.
lv1.AddSingleLine2(cs.Initialize.Typeface(Typeface.FONTAWESOME).VerticalAlign(5dip).Append(Chr(0xE531)).Append(" 9 Reglas de Superviviencia").PopAll, pageList.Get(0))
 
Upvote 0

JhoeyBoy

Member
Licensed User
Longtime User
I have downloaded the FontAwesome Library, see image, were i put this files to use this in designer layout.
Capture.PNG


thanks
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top