Schore
Schore

Reputation: 133

Make checkbox look disabled in Android

I want to make a checkbox that offers three different states: unchecked, "half" checked and checked. To stay consistent with the current system style I'd like to use the grayed-out/disabled style for the "half" checked state, but I cant find any drawable that defines this look. How can I make a checkbox look disabled without really disabling it? Thanks in advance!

Upvotes: 5

Views: 3644

Answers (3)

user3570982
user3570982

Reputation: 559

I spent a long time trying to do exactly what you requested, and finally realized that a fairly simple solution would work (for me, at least). Instead of using my own drawables and styles, or trying to get at undocumented system resources, I just reduce the opacity for the half-checked state, and restore the opacity for the full-checked state. For example, I do the following:

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

This produces a result like the following: half-checked state

Upvotes: 8

Dave
Dave

Reputation: 298

When I've needed similar things, I've setBackground or setTextColor. You may also be able to make use of setPressed so your three states are (checked, unchecked, and pressed).

Upvotes: 0

smk
smk

Reputation: 5842

Since a checkbox is a type of button , any of the states that apply to a button is applicable to it too.

here is a discussion on the different states for an android button How to grey out a button?

Upvotes: 0

Related Questions