Hide a preference in a PreferenceActivity

If your logout button (Preference) is in the PreferenceScreen, do this:

PreferenceScreen screen = getPreferenceScreen();
Preference logout = findPreference("logout");
screen.removePreference(logout);

Else if your logout button (Preference) is in a PreferenceCategory (which is inside a PreferenceScreen), do this:

PreferenceCategory category = (PreferenceCategory) findPreference("category_name");
Preference logout = findPrefence("logout");
category.removePreference(logout);

You can put whatever your preferences name is, this is for example for a logout preference, if you have another Preference (eg CheckBoxPreference) you need to cast that specific Preference before findPreference.


Something like that should works:

Preference p = findPreference("your_preference_key");
getPreferenceScreen().removePreference(p);