Android Question Incompatible types: Typeface cannot be converted to B4XFont

Theera

Expert
Licensed User
Longtime User
I'm creating the library B4XEnhancedUIButton is alike expert's UISwitch library .I set my font is "BLK BangLi-Ko-Sa-Na Regular.ttf" and my code is
B4X:
Private Sub AdjustTextOverlayFont
    If xTextOverlay.IsInitialized = False Then Return
 

    'Calculate font's size equal to button's size

    Dim baseSize As Float = Min(mBase.Width, mBase.Height) / 8
    
    If baseSize < 10 Then baseSize = 10.0
    If baseSize > 24 Then baseSize = 24.0
 

    'Create B4XFont
    If mCustomFontFile <> "" Then
        Log(mCustomFontFile)
        Try
            #If B4A
            Dim tf As Typeface
            tf = Typeface.LoadFromAssets(mCustomFontFile)
         
            xTextOverlay.Font = xui.CreateFont2(tf, baseSize)
         
            #Else If B4i
            xTextOverlay.Font = xui.CreateFont(mCustomFontFile, baseSize)
         
            #Else If B4J
            xTextOverlay.Font = xui.CreateFont2(xui.LoadFont(File.DirAssets, mCustomFontFile, baseSize), baseSize)
         
            #End If
        Catch
            xTextOverlay.Font = xui.CreateDefaultFont(baseSize)
        End Try
    Else
        xTextOverlay.Font = xui.CreateDefaultFont(baseSize)
    End If
End Sub
My error message while compiling
Compiling generated Java code. Error
B4A line: 221
xTextOverlay.Font = xui.CreateFont2(tf, baseSiz
src\b4a\example\b4xenhanceduibutton.java:90: error: incompatible types: Typeface cannot be converted to B4XFont
_xtextoverlay.setFont(_xui.CreateFont2((anywheresoftware.b4a.objects.B4XViewWrapper.B4XFont)(_tf.getObject()),_basesize));
 
Last edited:
Top