PreferenceFragment
public
abstract
class
PreferenceFragment
extends Fragment
implements
PreferenceManager.OnPreferenceTreeClickListener,
PreferenceManager.OnDisplayPreferenceDialogListener,
PreferenceManager.OnNavigateToScreenListener,
DialogPreference.TargetFragment
| java.lang.Object | ||
| ↳ | android.app.Fragment | |
| ↳ | androidx.preference.PreferenceFragment | |
This class is deprecated.
Use PreferenceFragmentCompat instead
Shows a hierarchy of Preference objects as lists. These preferences will automatically
save to SharedPreferences as the user interacts with them. To retrieve
an instance of SharedPreferences that the preference hierarchy in this
fragment will use, call
PreferenceManager.getDefaultSharedPreferences(android.content.Context) 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(PreferenceScreen).
The preference hierarchy can be formed in multiple ways:
- From an XML file specifying the hierarchy
- From different
Activitiesthat each specify its own preferences in an XML file viaActivitymeta-data - From an object hierarchy rooted with
PreferenceScreen
To inflate from XML, use the addPreferencesFromResource(int). 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(PreferenceScreen).
As a convenience, this fragment implements a click listener for any preference in the current
hierarchy, see onPreferenceTreeClick(Preference).
Developer Guides
For information about building a settings screen using the AndroidX Preference library, see Settings.
See also:
Summary
Nested classes | |
|---|---|
interface |
PreferenceFragment.OnPreferenceDisplayDialogCallback
Interface that the fragment's containing activity should implement to be able to process preference items that wish to display a dialog. |
interface |
PreferenceFragment.OnPreferenceStartFragmentCallback
Interface that the fragment's containing activity should implement to be able to process preference items that wish to switch to a specified fragment. |
interface |
PreferenceFragment.OnPreferenceStartScreenCallback
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. |
Constants | |
|---|---|
String |
ARG_PREFERENCE_ROOT
This constant is deprecated.
Use |
Inherited constants |
|---|
Public constructors | |
|---|---|
PreferenceFragment()
|
|
Public methods | |
|---|---|
void
|
addPreferencesFromResource(int preferencesResId)
This method is deprecated.
Use |
<T extends Preference>
T
|
findPreference(CharSequence key)
This method is deprecated.
Use |
final
RecyclerView
|
getListView()
This method is deprecated.
Use |
PreferenceManager
|
getPreferenceManager()
This method is deprecated.
Use |
PreferenceScreen
|
getPreferenceScreen()
This method is deprecated.
Use |
void
|
onCreate(Bundle savedInstanceState)
|
RecyclerView.LayoutManager
|
onCreateLayoutManager()
This method is deprecated.
Use |
abstract
void
|
onCreatePreferences(Bundle savedInstanceState, String rootKey)
This method is deprecated.
Use |
RecyclerView
|
onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
This method is deprecated.
Use |
View
|
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
void
|
onDestroyView()
|
void
|
onDisplayPreferenceDialog(Preference preference)
This method is deprecated.
Use |
void
|
onNavigateToScreen(PreferenceScreen preferenceScreen)
This method is deprecated.
Use |
boolean
|
onPreferenceTreeClick(Preference preference)
This method is deprecated.
Use |
void
|
onSaveInstanceState(Bundle outState)
|
void
|
onStart()
|
void
|
onStop()
|
void
|
onViewCreated(View view, Bundle savedInstanceState)
|
void
|
scrollToPreference(Preference preference)
This method is deprecated.
Use |
void
|
scrollToPreference(String key)
This method is deprecated.
Use |
void
|
setDivider(Drawable divider)
This method is deprecated.
Use |
void
|
setDividerHeight(int height)
This method is deprecated.
Use |
void
|
setPreferenceScreen(PreferenceScreen preferenceScreen)
This method is deprecated.
Use |
void
|
setPreferencesFromResource(int preferencesResId, String key)
This method is deprecated.
Use |
Protected methods | |
|---|---|
Adapter
|
onCreateAdapter(PreferenceScreen preferenceScreen)
This method is deprecated.
Use |
Inherited methods | |
|---|---|