Android Question [Solved] How to use new versions of Material Design Icons in AS Tab Menu

pliroforikos

Active Member
Licensed User
Hello everyone
I'm trying to use new version of Material Design Icons.

So i downloaded, copied in files folder, imported with files manager and used the code bellow to show icons.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ASTabMenu_horizontal As ASTabMenu
End Sub

Public Sub Initialize
  
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("frm_main")
    B4XPages.SetTitle(Me,"AS Tab Menu Example V1.20")
    ASTabMenu_horizontal.SelectedTabTextColor = xui.Color_Green
    ASTabMenu_horizontal.BeginUpdate
    ASTabMenu_horizontal.AddTab(xui.Color_White,"Menu1", FontToBitmap(Chr(0xF1028),True,30,xui.Color_BLACK),"")
    ASTabMenu_horizontal.AddTab(xui.Color_White,"Menu2", FontToBitmap(Chr(0xF179),False,30,xui.Color_BLACK),"")
    ASTabMenu_horizontal.AddTab(xui.Color_White,"Menu3", FontToBitmap(Chr(0xF11B),False,30,xui.Color_BLACK),"")
    ASTabMenu_horizontal.EndUpdate

    Sleep(0)
  
    ASTabMenu_horizontal.CurrentTabUnderlineGravity = ASTabMenu_horizontal.CurrentTabUnderlineGravity_BOTTOMRIGHT
    ASTabMenu_horizontal.TabStripMode = False
End Sub


Sub Chr32(code As Long) As String
    Dim bc As ByteConverter
    Dim c() As Byte = bc.LongsToBytes(Array As Long(code))
    For i = 0 To c.Length - 1
        Log(c(i))
    Next
    Return BytesToString(c, 0, c.Length, "UTF32")
End Sub


'Convert fonts a icon bitmap
Public Sub FontToBitmap (FontText As String, IsMaterialIcons As Boolean , FontSize As Int, FontColor As Int) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
    Dim cvs1 As B4XCanvas
    cvs1.Initialize(p)
    Dim t As B4XFont
'    Dim IconsFont As B4XFont
    If IsMaterialIcons Then
        t =  xui.CreateFont(Typeface.LoadFromAssets("materialdesignicons-webfont.ttf"), FontSize)
    Else
        t =  xui.CreateFont(Typeface.FONTAWESOME, FontSize)
    End If
  
  
    Dim r As B4XRect = cvs1.MeasureText(FontText, xui.CreateFont2(t, FontSize))
    Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
    cvs1.DrawText(FontText, cvs1.TargetRect.CenterX, BaseLine, xui.CreateFont2(t, FontSize), FontColor, "CENTER")
    cvs1.Invalidate
    Dim b As B4XBitmap = cvs1.CreateBitmap
    cvs1.Release
    Return b
End Sub


'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub ASTabMenu_horizontal_TabClick(index As Int)
    Log("TabClick: " & index)
End Sub

Unfortunately i can't show the icons of the library. I believe that is something about the bigger hex numbers from the previous versions but i am not sure. I used Chr32 function to return UTF32 but without success too.
ASTabMenu_horizontal.FontToBitmap is not working either.

Any advice is welcome!
 

Attachments

  • Project.zip
    434.5 KB · Views: 141

angel_

Well-Known Member
Licensed User
Longtime User
I see these icons

Screenshot_B4A_as_tabmenu.png
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Tips.
Step 1. See sheet

Step 2. hex codepoint
Sample code F1028, F1790 and F11B0

Step 3 Use Sub Convert
UnicodeToString(0xF1028)
B4X:
Sub UnicodeToString (code As Int) As String
    Dim bc As ByteConverter
    Dim b() As Byte = bc.IntsToBytes(Array As Int(code))
    Return BytesToString(b, 0, 4, "UTF32")
End Sub
Change:
ASTabMenu_horizontal.AddTab(xui.Color_White,"Menu1", FontToBitmap(UnicodeToString(0xF1028),True,30,xui.Color_BLACK),"")

Sample label and image
1637466624246.png
 
Last edited:
Upvote 0

pliroforikos

Active Member
Licensed User
I realized after checking again ttf file that it was older version from the one in official webpage. Problem solved.
Thank you for the instructions.
 
Upvote 0
Top