2

Here's my code:

<PreferenceCategory
   android:summary="Fade information"
   android:title="Fade Effects"> 

   <CheckBoxPreference
     android:title="Fade In/Out"
            android:defaultValue="false"         
            android:key="fadeIn"/> 

   <CheckBoxPreference
     android:title="Heartbeat"
            android:defaultValue="false"   
            android:key="heartbeat" />  

   <CheckBoxPreference
     android:title="Pulse"
            android:defaultValue="false"               
            android:key="pulse" />  

   <CheckBoxPreference
     android:title="None"
            android:defaultValue="true"
            android:key="none" />  
</PreferenceCategory>

I'm basically trying to figure out how to make those CheckBoxes appear as they are, but having them unclickable by the user.

SynGT
  • 23
  • 1
  • 3

3 Answers3

7

Using android:enabled="false" is incorrect as this actually completely disables a View (it also greys it out which is the main issue). What you want to do instead is:

android:clickable="false"

This simply stops the user clicking the View but doesn't officially 'disable' it. I think that's more what you are looking for.

edwoollard
  • 12,245
  • 6
  • 43
  • 74
  • Clickable as false didn't have any effect on the Preference. – Sagar Aug 26 '17 at 15:24
  • There is no `android:clickable` attribute [on `CheckBoxPreference`](https://developer.android.com/reference/android/preference/CheckBoxPreference.html), which is what this question is about. – CommonsWare Aug 26 '17 at 15:28
2

You can use android:selectable="false" in xml if you don't wish to gray out the CheckboxPreference.

Thracian
  • 43,021
  • 16
  • 133
  • 222
1

Use android:enabled="false" from your XML, or setEnabled() in Java code.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491