android:visibility attribute in preferences xml not working? (Android 2.3) android:visibility attribute in preferences xml not working? (Android 2.3) xml xml

android:visibility attribute in preferences xml not working? (Android 2.3)


android:visibility is used to show and hide Views but it's not valid for a Preference. The documentation for Preference lists the available XML attributes, but none of them are what you want.

It is, however, possible to add and remove preferences from a PreferenceScreen programatically.


For AndroidX users, add this directly to your preference XML

app:isPreferenceVisible="false"


You have to use setVisible method to change the visibility.

First, initialize the checkbox preference.

CheckBoxPreference showSigPreference = (CheckBoxPreference) findPreference("show_sig");

then

// Show the check box preferenceshowSigPreference.setVisible(true);// Hide the check box preferenceshowSigPreference.setVisible(false);