Android Question How to insert FontAwesome & MaterialIcons in code

DickD

Active Member
Licensed User
I have tried the following code to insert icons into a layout created completely in code. It doesn't work. I just get a rectangle with a an X inside. Ditto with Material Icons. A simple sample would be appreciated. A picture is always worth a thousand words.

B4X:
'Search Button
Dim lblFontAwesome As Label
lblFontAwesome.Initialize("")
SearchButton.Initialize("SearchButton")
SearchButton.Typeface = lblFontAwesome.Typeface
SearchButton.Text = Chr(0xF179)
SearchButton.Background = cd
SearchButton.TextSize = 20
Activity.AddView(SearchButton, 70dip,500dip,70dip, 50dip)
 

MarcoRome

Expert
Licensed User
Longtime User
Do you use B4A 6.80 ?

B4X:
Dim cs As CSBuilder
cs.Initialize.Typeface(Typeface.FONTAWESOME).Append(Chr(0xF179)).PopAll
SearchButton.Text = cs
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Erel say:
2. Add an invisible label named lblFontAwesome with the designer and set its font to FontAwesome.
i dont think that you add this with the Designer, right ?
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Right. The layout is totally created in code.
If you continue to read thread you found also this:
The reason that this workaround is required is that the font files are only added when you actually use them in the designer.

So if you add, you have in another case isnt possible
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…