Make the checkbox disabled in Android

I want to check a box that offers three different states: unverified, "half" checked and checked. To stay in line with the current system style, I would like to use a gray / disabled style for the "half" checked state, but I cannot find any drawable that defines this view. How can I disable checkbox without disabling it? Thanks in advance!

+4
source share
3 answers

For a long time I tried to do exactly what you asked, and finally realized that a fairly simple solution would work (at least for me). Instead of using my own drawings and styles or trying to get undocumented system resources, I just reduce the opacity for a semi-defined state and restore transparency for a state with full control. For example, I do the following:

if (half_checked) checkBox.setAlpha(0.4f); else checkBox.setAlpha(1.0f); 

This leads to the following: half-checked state

+4
source

Because the check box is a type of button, any of the states that apply to the button also applies to it.

different states for the android button are discussed here How to cut a button?

0
source

When I needed such things, I have setBackground or setTextColor. You can also use setPressed to have your three states (checked, unchecked and clicked).

0
source

All Articles