Android Question B4XComboBox - Font on B4A

Nicolás Cieri

Active Member
Licensed User
Hi!,

How can I change the Font of B4XComboBox in B4A??

I know I can do this by designer, but I need my own Font or typeface.

Is possible?

Thanks a lot.
 

mangojack

Well-Known Member
Licensed User
Longtime User
the B4XCombobox makes use of Spinner which from what I gather does not have a Font method.

Try this code which uses the CSBuilder . Make sure to copy your font to the assets folder.

B4X:
lstItems.AddAll(Array As String("Dog", "Cat", "Bird"))
    
    Dim cs As CSBuilder
    Dim myFont As Typeface = Typeface.LoadFromAssets("MyFont.ttf") 
    
    For i = 0 To lstItems.Size -1
        B4XComboBox1.cmbBox.AddAll(Array(cs.Initialize.Typeface(myFont).Append(lstItems.Get(i)).PopAll))
    Next
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
mj's code works very well, but if you do not want to expose the native spinner (cmbBox), you can use this code as an alternative
B4X:
Dim l2 As List
    l2.Initialize
    For i =0 To lstItems.Size -1
        l2.Add(cs.Initialize.Typeface(myFont).Append(lstItems.Get(i)).PopAll)
    Next
    B4XComboBox1.SetItems(l2)
 
Upvote 0
Top