PreferenceFragment

Deprecated

Use PreferenceFragmentCompat instead

(SESL variant) Shows a hierarchy of Preference objects as lists. These preferences will automatically save to android.content.SharedPreferences as the user interacts with them. To retrieve an instance of android.content.SharedPreferences that the preference hierarchy in this fragment will use, call getDefaultSharedPreferences with a context in the same package as this fragment.

Furthermore, the preferences shown will follow the visual style of system preferences. It is easy to create a hierarchy of preferences (that can be shown on multiple screens) via XML. For these reasons, it is recommended to use this fragment (as a superclass) to deal with preferences in applications.

A PreferenceScreen object should be at the top of the preference hierarchy. Furthermore, subsequent PreferenceScreen in the hierarchy denote a screen break--that is the preferences contained within subsequent PreferenceScreen should be shown on another screen. The preference framework handles this by calling onNavigateToScreen.

The preference hierarchy can be formed in multiple ways:

To inflate from XML, use the addPreferencesFromResource. The root element should be a PreferenceScreen. Subsequent elements can point to actual Preference subclasses. As mentioned above, subsequent PreferenceScreen in the hierarchy will result in the screen break.

To specify an object hierarchy rooted with PreferenceScreen, use setPreferenceScreen.

As a convenience, this fragment implements a click listener for any preference in the current hierarchy, see onPreferenceTreeClick.

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
Interface that the fragment's containing activity should implement to be able to process preference items that wish to display a dialog.
Link copied to clipboard
Interface that the fragment's containing activity should implement to be able to process preference items that wish to switch to a specified fragment.
Link copied to clipboard
Interface that the fragment's containing activity should implement to be able to process preference items that wish to switch to a new screen of preferences.

Properties

Link copied to clipboard
val ARG_PREFERENCE_ROOT: String = "androidx.preference.PreferenceFragmentCompat.PREFERENCE_ROOT"
Fragment argument used to specify the tag of the desired root PreferenceScreen object.

Functions

Link copied to clipboard
open fun addPreferencesFromResource(@XmlRes preferencesResId: Int)
Inflates the given XML resource and adds the preference hierarchy to the current preference hierarchy.
Link copied to clipboard
Link copied to clipboard
Finds a Preference based on its key.
Link copied to clipboard
A wrapper for getParentFragment which is v17+.
Link copied to clipboard
Link copied to clipboard
Returns the PreferenceManager used by this fragment.
Link copied to clipboard
Gets the root of the preference hierarchy that this fragment is showing.
Link copied to clipboard
fun needToRefeshSwitch(preferenceGroupAdapter: PreferenceGroupAdapter, i: Int, i2: Int): Boolean
Link copied to clipboard
Link copied to clipboard
open fun onCreate(@Nullable savedInstanceState: Bundle)
Link copied to clipboard
abstract fun onCreatePreferences(@Nullable savedInstanceState: Bundle, rootKey: String)
Called during onCreate to supply the preferences for this fragment.
Link copied to clipboard
open fun onCreateRecyclerView(@NonNull inflater: LayoutInflater, @NonNull parent: ViewGroup, @Nullable savedInstanceState: Bundle): RecyclerView
Creates the RecyclerView used to display the preferences.
Link copied to clipboard
open fun onCreateView(@NonNull inflater: LayoutInflater, @Nullable container: ViewGroup, @Nullable savedInstanceState: Bundle): View
Link copied to clipboard
open fun onDestroyView()
Link copied to clipboard
Called when a preference in the tree requests to display a dialog.
Link copied to clipboard
open fun onNavigateToScreen(@NonNull preferenceScreen: PreferenceScreen)
Called by onClick in order to navigate to a new screen of preferences.
Link copied to clipboard
Called when a preference in the tree rooted at this has been clicked.
Link copied to clipboard
open fun onSaveInstanceState(@NonNull outState: Bundle)
Link copied to clipboard
open fun onStart()
Link copied to clipboard
open fun onStop()
Link copied to clipboard
open fun onViewCreated(@NonNull view: View, @Nullable savedInstanceState: Bundle)
Link copied to clipboard
open fun scrollToPreference(@NonNull preference: Preference)
Link copied to clipboard
open fun seslSetRoundedCorner(enabled: Boolean)
Link copied to clipboard
open fun setDivider(@Nullable divider: Drawable)
Sets the Drawable that will be drawn between each item in the list.
Link copied to clipboard
open fun setDividerHeight(height: Int)
Sets the height of the divider that will be drawn between each item in the list.
Link copied to clipboard
open fun setPadding(left: Int, top: Int, right: Int, bottom: Int)
Link copied to clipboard
open fun setPreferenceScreen(preferenceScreen: PreferenceScreen)
Sets the root of the preference hierarchy that this fragment is showing.
Link copied to clipboard
open fun setPreferencesFromResource(@XmlRes preferencesResId: Int, @Nullable key: String)
Inflates the given XML resource and replaces the current preference hierarchy (if any) with the preference hierarchy rooted at key.