SetCBDrawable2FromFont(ckbox, Chr(0xF096), Chr(0xF046), 24, Colors.White)
Public Sub SetCBDrawable2FromFont(CB As View, sUnchecked As String, sChecked As String, Size As Int, color As Int)
Dim SLD As StateListDrawable
SLD.Initialize
Dim Unchecked,Checked As Bitmap
Dim UncheckedBMD,CheckedBMD As BitmapDrawable
Unchecked.Initialize3(TextToBitmap(sUnchecked, False, Size, color))
Checked.Initialize3(TextToBitmap(sChecked, False, Size, color))
UncheckedBMD.Initialize(Unchecked)
CheckedBMD.Initialize(Checked)
'Add to the StateList Drawable
SLD.AddState(SLD.State_Checked,CheckedBMD)
SLD.AddState(SLD.State_Unchecked,UncheckedBMD)
SLD.AddCatchAllState(UncheckedBMD)
'Add SLD to the Checkbox
Dim JO As JavaObject = CB
JO.RunMethod("setButtonDrawable",Array As Object(SLD))
'CB.Background = SLD
End Sub
Public Sub TextToBitmap (text As String, IsMaterialIcons As Boolean, FontSize As Float, color As Int) As B4XBitmap
Dim xui As XUI
Dim p As Panel = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
Dim cvs1 As B4XCanvas
cvs1.Initialize(p)
Dim t As Typeface
If IsMaterialIcons Then t = Typeface.MATERIALICONS Else t = Typeface.FONTAWESOME
Dim fnt As B4XFont = xui.CreateFont(t, FontSize / Fontscale)
Dim r As B4XRect = cvs1.MeasureText(text, fnt)
Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
cvs1.DrawText(text, cvs1.TargetRect.CenterX, BaseLine, fnt, color, "CENTER")
Dim b As B4XBitmap = cvs1.CreateBitmap
cvs1.Release
Return b
End Sub