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
There is a really simple creative solution.
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
You can get something similar to that using SetColorAndBorder of B4XView
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").
@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