B4J Question FontAwesome in code gives me an square error

I'm trying to do a dynamic list with buttons, and put icons on the buttons, but when I put the icon on the button programmatically it gives me an square error
B4X:
Dim label As Button
label.Initialize("ListBtn")
CSSUtils.SetBackgroundColor(label,fx.Colors.White)
CSSUtils.SetBorder(label,1,fx.Colors.ARGB(255,196,196,196),4)
Dim b4x As B4XView = label
b4x.SetTextAlignment("CENTER","CENTER")
label.Enabled = True
label.Font =  Main.xui.CreateFontAwesome(10)
label.Text = Chr(0xF1F8)
label.TextColor = fx.Colors.Red

square_error.png

I have tried to use a bigger font size, and a smaller too, but it didn't change anything. I also tried to use MaterialIcons, but it doesn't change anything either.
 
Better to switch to B4XView right after you initialize the button, and use the B4XView methods.
That didnt work too, it gives the same square. I'm using FontAwesome programmatically in another place in the code, but it is in a label, and works just fine. But with the buttons doesn't work propperly.
The oder place I'm using FontAwesome in the code:
For i=0 To Opcoes.Length-1
        Dim Op As Pane
        Dim PnlHighlight As Pane
        Dim Label_Text As Label
        Dim Label_Icon As Label
        
        Op.Initialize("")
        Op.SetSize(220,40)
        CSSUtils.SetBackgroundColor(Op,fx.Colors.RGB(61,122,179))       
        
        PnlHighlight.Initialize("")
        PnlHighlight.SetSize(218,30)
        CSSUtils.SetBackgroundColor(PnlHighlight,fx.Colors.RGB(0,58,112))
        CSSUtils.SetBorder(PnlHighlight,0,fx.Colors.Black,6)
        PnlHighlight.Visible = False
        Opcoes(i).PnlHighlight = PnlHighlight
        Op.AddNode(PnlHighlight,0,5,218,30)
        
        Label_Text.Initialize("LabelMenu")
        Label_Text.SetSize(130,30)
        Label_Text.Tag = Opcoes(i).tag
        Label_Text.Style =  "-fx-font-size: 12;"
        Label_Text.Text = Opcoes(i).text
        
        Label_Icon.Initialize("LabelMenu")
        Label_Icon.SetSize(30,30)
        Label_Icon.Tag = Opcoes(i).tag
        Label_Icon.Font = Main.xui.CreateFontAwesome(16)
        Label_Icon.Text = Opcoes(i).icon   
    
        Op.AddNode(Label_Icon,30,5,30,30)
        Op.AddNode(Label_Text,70,5,130,30)
        Opcoes(i).Pane = Op
        
        OpcoesMenu_Panes.Add(Opcoes(i))
    Next
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Label_Text.Style = "-fx-font-size: 12;"
This is not needed and is a mistake.
The sooner you switch to B4XView the better.


I'm able to set the font of buttons:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As B4XView
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Button1.Font = xui.CreateFontAwesome(30)
    Button1.Text = Chr(0xF17B)
End Sub

1673589932343.png
 
Upvote 0
Top