Maybe ready code example ?I normally use a panel, and 2 labels, 1 for the icon, and one for the text, so I can customize it as I want
Dim cs As TextFlow
cs.Initialize.Append(Chr(0xF015)).Color(0xFF01FF20).Font(xui.CreateFontAwesome(60))
cs.Append(Chr(160) & "HOME").Size(38)
Pane2.AddView(cs.PopAll, 10, 10, 200, 100)
Dim cs As TextFlow
cs.Initialize.Append("1 2 3").Color(xui.Color_Red).Underline(True)
cs.Append(" 4 5 6 ").Color(xui.Color_Green).Font(xui.CreateDefaultBoldFont(17))
cs.Append("7 8 9").Color(xui.Color_Blue).Strikethrough(True).Font(xui.CreateDefaultFont(20))
cs.Append(CRLF)
cs.Append(Chr(0xF015)).Color(0xFF01FF20).Font(xui.CreateFontAwesome(60))
cs.Append(Chr(160) & "HOME").Size(38)
Pane2.AddView(cs.PopAll, 10, 10, 200, 100)
Dim cs As TextFlow
cs.Initialize.Append("1 2 3").Color(xui.Color_Red).Underline(True)
cs.Append(" 4 5 6 ").Color(xui.Color_Green).Font(xui.CreateDefaultBoldFont(17))
cs.Append("7 8 9").Color(xui.Color_Blue).Strikethrough(True).Font(xui.CreateDefaultFont(20))
cs.Append(CRLF)
cs.Append(Chr(0xF015)).Color(0xFF01FF20).Font(xui.CreateFontAwesome(60))
cs.Append(Chr(160) & "HOME").Size(38)
Pane2.AddView(cs.PopAll, 10, 10, 200, 100)
cs.Initialize.Append(Chr(0xF209)).Color(xui.Color_White).Font(xui.CreateFontAwesome(28)).Color(xui.Color_White)
cs.Append(Chr(160) & Chr(160) & "Bottone uno").Size(20).Color(xui.Color_White)
Pane3.AddView(cs.PopAll, 15, 12, 200, 10)
Public Sub SetNodeImage(n As Node, ImageDir As String, ImageFileName As String, Width As Int, Height As Int, ContentDisplay As String)
'Check that path and filename are valid:
If ImageDir = "" Or ImageFileName = "" Then Return
'Set the button image:
Dim iv As ImageView
Dim nJo As JavaObject = n
iv = nJo.RunMethod("getGraphic", Null)
If iv.IsInitialized Then
iv.SetImage(fx.LoadImageSample(ImageDir, ImageFileName, iv.Width, iv.Height))
Else
iv.Initialize("")
If Width > -1 Then
iv.Width = Width
End If
If Height > -1 Then
iv.Height = Height
End If
iv.SetImage(fx.LoadImageSample(ImageDir, ImageFileName, iv.Width, iv.Height))
nJo.RunMethod("setGraphic", Array(iv))
Dim cd As JavaObject
cd.InitializeStatic("javafx.scene.control.ContentDisplay")
nJo.RunMethod("setContentDisplay", Array(cd.RunMethod("valueOf", Array(ContentDisplay))))
End If
End Sub
SetNodeImage(bt,File.DirAssets,icon,16,16,"LEFT")
Is that possible with B4A... and how ?I use this ... for exampleB4X:Public Sub SetNodeImage(n As Node, ImageDir As String, ImageFileName As String, Width As Int, Height As Int, ContentDisplay As String) 'Check that path and filename are valid: If ImageDir = "" Or ImageFileName = "" Then Return 'Set the button image: Dim iv As ImageView Dim nJo As JavaObject = n iv = nJo.RunMethod("getGraphic", Null) If iv.IsInitialized Then iv.SetImage(fx.LoadImageSample(ImageDir, ImageFileName, iv.Width, iv.Height)) Else iv.Initialize("") If Width > -1 Then iv.Width = Width End If If Height > -1 Then iv.Height = Height End If iv.SetImage(fx.LoadImageSample(ImageDir, ImageFileName, iv.Width, iv.Height)) nJo.RunMethod("setGraphic", Array(iv)) Dim cd As JavaObject cd.InitializeStatic("javafx.scene.control.ContentDisplay") nJo.RunMethod("setContentDisplay", Array(cd.RunMethod("valueOf", Array(ContentDisplay)))) End If End Sub
B4X:SetNodeImage(bt,File.DirAssets,icon,16,16,"LEFT")
where bt is button and icon a file name of icon (icon.png)
'https://www.b4x.com/android/forum/threads/fontawesome-to-bitmap.95155/#post-603250
Dim bmp As B4XBitmap = SetFontToBitmap(Chr(0xF085), xui.CreateFontAwesome(32), xui.Color_Blue)
Button1.Text = "TYPE Button with FontAwesome"
SetImageToView(Button1, bmp, "LEFT")
Dim bmp As B4XBitmap = SetFontToBitmap(Chr(0xE438), xui.CreateMaterialIcons(32), xui.Color_Red)
Label5.Text = "Type Label with MaterialIcons"
SetImageToView(Label5, bmp, "LEFT")
Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "icon.png", 32, 32, True)
Button2.Text = "Type Button with Image"
SetImageToView(Button2, bmp, "LEFT")
Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "icon.png", 32, 32, True)
Label6.Text = "Type Label with Image"
SetImageToView(Label6, bmp, "LEFT")
Public Sub SetImageToView(view As B4XView, Image As B4XBitmap, Position As String)
Dim iv As ImageView
iv.Initialize("")
iv.SetImage(Image)
Dim jo As JavaObject
jo.InitializeStatic("javafx.scene.control.ContentDisplay")
view.As(JavaObject).RunMethod("setGraphic", Array(iv))
view.As(JavaObject).RunMethod("setContentDisplay", Array(jo.RunMethod("valueOf", Array(Position))))
End Sub
Dim bmp As B4XBitmap = SetFontToBitmap(Chr(0xE438), xui.CreateMaterialIcons(52), xui.Color_Red)
Button3.Text = "Button MaterialIcons"
Button3.TextSize = 14
Button3.TextColor = xui.Color_Blue
SetImageToView(Button3, bmp, "TOP")