Android Question checkbox not visible when not checked

tufanv

Expert
Licensed User
Longtime User
Hello,

The checkbox's box is not visible until the user checks it. Is there any way to make it visible, because when it is not checked only the text is visible and user can't understand that it is clickable.

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Upload a project which shows the issue
 
Upvote 0
D

Deleted member 103

Guest
to the point. Thanks !
Or you use this code:

B4X:
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
 
Upvote 0
Top