Android Question CheckBox color and alignment

red30

Well-Known Member
Licensed User
Longtime User
Is it possible to remove (make transparent) the "square" to which the checkmark is located? That is, only one check mark is displayed.
When I set the alignment to the center, only the text is aligned, and the checkbox itself remains always on the left. Is it possible to make both text and checkmark alignment in the center?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to replace the two drawables with StateListDrawable.

When I set the alignment to the center, only the text is aligned, and the checkbox itself remains always on the left. Is it possible to make both text and checkmark alignment in the center?
Not automatically. You can measure the text width and change the checkbox position.

 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
You will need to replace the two drawables with StateListDrawable.
I have visited to use this example:
B4X:
SetColorTintList(CheckBox1,Colors.Greed,Colors.Red,Colors.Blue)
Sub SetColorTintList(CB As CheckBox,Checked As Int,Enabled As Int,Disabled As Int)
    Dim States(3,1) As Int

    States(0,0) = 16842912   'Checked
    States(1,0) = 16842910    'Enabled
    States(2,0) = -16842910 'Disabled

    Dim Color(3) As Int = Array As Int(Checked,Enabled,Disabled)

    Dim CSL As JavaObject
    CSL.InitializeNewInstance("android.content.res.ColorStateList",Array As Object(States,Color))
    Dim CB1 As JavaObject = CB
    CB1.RunMethod("setButtonTintList",Array As Object(CSL))

End Sub
I get that the color of the square and checkmark changes. And I only need to leave a checkmark (black), and make the square transparent.
Not automatically. You can measure the text width and change the checkbox position.

I don't understand how can I use this with CheckBox? Can you give me a small example?
 
Upvote 0
Top