Yonah Karp
Yonah Karp

Reputation: 671

Grey out a preference in settings android

I want to grey out one of the panes in the settings, like this (bottom preference)

(note: I edited the design image as not to give away info about the app. I've signed a non-disclosure agreement and don't want to get fired)

like this

any help would be appreciated

Upvotes: 2

Views: 2871

Answers (2)

ZikManxx
ZikManxx

Reputation: 43

Looking to the Answer of RamiReddy, is a bit old so i will put below the updated one. I hope will help someone.

This is worked for me. My code:

Preference key_remove_ads = findPreference(getString(R.string.key_remove_ads_));
            key_remove_ads.setEnabled(false);
            key_remove_ads.setShouldDisableView(true);

And this is my xml:

android:defaultValue="@string/remove_ads_title_small"
android:key="@string/key_remove_ads_"
android:summary="@string/remove_ads_title_small"
android:title="@string/remove_ads_title" />

Upvotes: 1

RamiReddy
RamiReddy

Reputation: 1089

Set setShouldDisableView(true). Then, set setEnabled(false). This should make the item appear disabled (grey) and not clickable.

Upvotes: 2

Related Questions