Is possible to hide a preference in a PreferenceScreen? I don't need to disable it, it must be invisible (sometimes)
Important: I need to keep the min API level 7+
If your logout button (Preference) is in the PreferenceScreen, do this:
PreferenceScreen screen = getPreferenceScreen();
Preference logout = findPreference("logout");
if(screen != null && logout != null)
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");
if(category != null && logout != null)
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With