Issues with dual-pane preference screens

Problem Solved With how popular this question has become, I decided to revisit this issue again and see if I could find a resolution…and I did. Found a nice little work around that solves the single pane showing instead of dual pane and ensuring a header is always pre-selected when in dual pane mode. If … Read more

How to show and hide preferences on Android dynamically?

From a PreferenceActivity call Preference somePreference = findPreference(SOME_PREFERENCE_KEY); PreferenceScreen preferenceScreen = getPreferenceScreen(); preferenceScreen.removePreference(somePreference); you can later call: preferenceScreen.addPreference(somePreference); The only a little bit tricky part is getting the order correct when adding back in. Look at PreferenceScreen documentation, particularly it’s base class, PreferenceGroup for details. Note: The above will only work for immediate children of … Read more

PreferenceFragment – Difference between getPreferenceManager() and getPreferenceScreen()?

The core difference is in their names, PreferenceManger grants access to different functionalities to the developer for managing SharedPreferences, such as retrieving the map of current preference values or setting user preferences. to their default values. PreferenceScreen handles displaying a screen of user preferences, so that the user can assign values to them. Sometimes this … Read more

Launch new activity from PreferenceActivity

Given you are using xml preferences you can add code right into the xml: <Preference android:title=”Some Title” android:summary=”Some Description”> <intent android:action=”android.intent.action.VIEW” android:targetPackage=”com.package.name” android:targetClass=”com.package.name.ActivityName” /> </Preference>

PreferenceFragmentCompat has padding on PreferenceCategory that I can’t get rid of

Actually there is a better hack to fix this, also with resource overriding: Create res/values-sw360dp-v13/values-preference.xml: <?xml version=”1.0″ encoding=”utf-8″?> <resources xmlns:tools=”http://schemas.android.com/tools”> <bool name=”config_materialPreferenceIconSpaceReserved” tools:ignore=”MissingDefaultResource,PrivateResource”>false</bool> <dimen name=”preference_category_padding_start” tools:ignore=”MissingDefaultResource,PrivateResource”>0dp</dimen> </resources> The <bool> fixes the default value of iconSpacePreserved for all Preference; The <dimen> fixes the PreferenceCategory. EDIT: If you are using androidx.preference:preference:1.1.0-alpha01 or above, you won’t need the … Read more