B4J Question Unicode Characters on Button

atiaust

Active Member
Licensed User
Longtime User
Hi All,

Can I use a unicode character eg 2190 left arrow on a button?

Thanks
 

atiaust

Active Member
Licensed User
Longtime User
Thanks Erel,

I did try that and it didn't work so I wasn't sure if the default font was the problem.

Is it better to use an icon on the button to show arrows?

Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is actually very simple to use FontAwesome and add nice icons:

SS-2016-08-11_09.56.10.png


1. Download FontAwesome: http://fontawesome.io/
2. Add FontAwesome.otf to the Files tab.
3. Load the font and set it to whichever controls you like:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private Button1 As Button
   Private awesome As Font
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   awesome = fx.LoadFont(File.DirAssets, "FontAwesome.otf", 20)
   Button1.Font = awesome
   Button1.Text = ""
End Sub

The nice thing is that you just need to copy the icon from this page: http://fontawesome.io/cheatsheet/ and use it like any other character. It will not appear properly in the IDE but it will work at runtime.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Just an addition in case the font awesome character is given as unicode.
This sub is used (thanks for that).

Example: Set button text to Battery Half = fa-battery-half []
B4X:
Button1.Text = UnescapeUnicode("\uf242")

upload_2016-8-23_10-23-43.png
 
Upvote 0

woniol

Active Member
Licensed User
Longtime User
Is it possible to add 'normal' text after the icon in the example from #4?
This doesn't work:
B4X:
Button1.Text = "" & "MyText"
 
Upvote 0
Top