Android Question (Solved) Checkbox Color

f0raster0

Well-Known Member
Licensed User
Longtime User
Hello Team,

We would like to modify some checkboxes in our App so that the small square turns white when they are not selected. How can we achieve this?

B4X:
If chkLedOnOff.Checked Then
        Sleep(10)
        ChkLedOnOff.Text="Led ON"
        chkLedOnOff.TextColor= Colors.White  
        'chkLedOnOff.TextColor color for the small aquare
    Else
        Sleep(10)
        chkLedOnOff.Text="Led OFF"
        chkLedOnOff.TextColor= Colors.Red
        'chkLedOnOff.TextColor color for the small aquare
    End If

Thank you.
Checkbox1.jpg
 
Last edited:

PaulMeuris

Active Member
Licensed User
There is a really simple creative solution.
1705724172948.png
1705724200408.png

Check out the designer settings of the example you can find in the attachment.
3 views... a blue panel that contains... a small white label and a transparent checkbox.
B4X:
Private Sub CheckBox1_CheckedChange(Checked As Boolean)
    If Checked Then
        CheckBox1.Text = "Led ON"
        CheckBox1.TextColor = xui.Color_White
    Else
        CheckBox1.Text = "Led OFF"
        CheckBox1.TextColor = xui.Color_Red
    End If
End Sub
 

Attachments

  • testenvironment43.zip
    10 KB · Views: 28
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
There is a really simple creative solution.
You can get something similar to that using SetColorAndBorder of B4XView
1705725425012.png

B4X:
Private Sub CheckBox1_CheckedChange(Checked As Boolean)
    Dim BorderColor As Int
    Dim BackgroundColor As Int
    Dim TextColor As Int
 
    BackgroundColor = xui.Color_Blue
 
    If Checked Then
        BorderColor = xui.Color_White
        TextColor = xui.Color_White
    Else
        BorderColor = xui.Color_Black
        TextColor = xui.Color_Red
    End If

    CheckBox1.As(B4XView).SetColorAndBorder(BackgroundColor, 2dip, BorderColor, 0)
    CheckBox1.As(B4XView).TextColor = TextColor
End Sub
[As(B4XView) is not necessary if you have declared the Checkbox as B4XView, which is best done for cross-platform programming]


Anyway, that's exactly why I developed this simple B4XView, to be able to use any image I want (obviously "adding" a Label to it, if it should be a "Checkbox").
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
@LucaMs , the code you presented doesn't answer the question.
In the OFF state the checkbox square doesn't have a white background!
@PaulMeuris, I wanted to enhance the visibility of the small square borders, as it is initially set to a dark color and my backgroudn is also dark. Thank you for your assistance

@LucaMs I used your link as below, thank you very much it works great!
B4X:
If chkLedOnOff.Checked Then
        Sleep(10)
        ChkLedOnOff.Text="Led ON"
        chkLedOnOff.TextColor= Colors.White 
        SetButtonTintList(chkLedOnOff, Colors.Red, Colors.Green)
    Else
        Sleep(10)
        'a=ByteA.HexToBytes
        'Manager1.WriteData
        chkLedOnOff.Text="Led OFF"
        chkLedOnOff.TextColor= Colors.Red
        SetButtonTintList(chkLedOnOff, Colors.Red, Colors.White)
    End If



Checkbox2.jpg
 
Last edited:
Upvote 0
Top