PreferenceFragment

Added in 1.0.0
Deprecated in 1.1.0

public abstract class PreferenceFragment extends Fragment implements PreferenceManager.OnPreferenceTreeClickListener, PreferenceManager.OnDisplayPreferenceDialogListener, PreferenceManager.OnNavigateToScreenListener, DialogPreference.TargetFragment

Known indirect subclasses

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.

Summary

Nested types

Interface that the fragment's containing activity should implement to be able to process preference items that wish to display a dialog.

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 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

static final String
ARG_PREFERENCE_ROOT = "androidx.preference.PreferenceFragmentCompat.PREFERENCE_ROOT"

This field is deprecated.

Use PreferenceFragmentCompat instead

Public constructors

Public methods

void
addPreferencesFromResource(@XmlRes int preferencesResId)

This method is deprecated.

Use PreferenceFragmentCompat instead

T

This method is deprecated.

Use PreferenceFragmentCompat instead

final RecyclerView

This method is deprecated.

Use PreferenceFragmentCompat instead

PreferenceManager

This method is deprecated.

Use PreferenceFragmentCompat instead

PreferenceScreen

This method is deprecated.

Use PreferenceFragmentCompat instead

void
onCreate(@Nullable Bundle savedInstanceState)

This method is deprecated.

@NonNull RecyclerView.LayoutManager

This method is deprecated.

Use PreferenceFragmentCompat instead

abstract void
onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey)

This method is deprecated.

Use PreferenceFragmentCompat instead

@NonNull RecyclerView
onCreateRecyclerView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup parent,
    @Nullable Bundle savedInstanceState
)

This method is deprecated.

Use PreferenceFragmentCompat instead

@NonNull View
onCreateView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

Use PreferenceFragmentCompat instead

void

This method is deprecated.

Use PreferenceFragmentCompat instead

boolean

This method is deprecated.

Use PreferenceFragmentCompat instead

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

Use PreferenceFragmentCompat instead

void

This method is deprecated.

Use PreferenceFragmentCompat instead

void

This method is deprecated.

Use PreferenceFragmentCompat instead

void
setDividerHeight(int height)

This method is deprecated.

Use PreferenceFragmentCompat instead

void

This method is deprecated.

Use PreferenceFragmentCompat instead

void
setPreferencesFromResource(
    @XmlRes int preferencesResId,
    @Nullable String key
)

This method is deprecated.

Use PreferenceFragmentCompat instead

Protected methods

@NonNull RecyclerView.Adapter

This method is deprecated.

Use PreferenceFragmentCompat instead

Inherited Constants

From android.content.ComponentCallbacks2
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

Inherited methods

From android.app.Fragment
void
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

This method is deprecated.

final boolean

This method is deprecated.

final Activity

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

final Bundle

This method is deprecated.

final FragmentManager

This method is deprecated.

Context

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final FragmentManager

This method is deprecated.

final Object

This method is deprecated.

final int

This method is deprecated.

final LayoutInflater

This method is deprecated.

LoaderManager

This method is deprecated.

final Fragment

This method is deprecated.

Transition

This method is deprecated.

final Resources

This method is deprecated.

final boolean

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final String
getString(int resId)

This method is deprecated.

final String

This method is deprecated.

final Fragment

This method is deprecated.

final int

This method is deprecated.

final CharSequence
getText(int resId)

This method is deprecated.

boolean

This method is deprecated.

View

This method is deprecated.

final int

This method is deprecated.

static Fragment
instantiate(Context context, String fname)

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

void
onActivityCreated(Bundle savedInstanceState)

This method is deprecated.

void
onActivityResult(int requestCode, int resultCode, Intent data)

This method is deprecated.

void
onAttach(Activity activity)

This method is deprecated.

void
onAttachFragment(Fragment childFragment)

This method is deprecated.

void

This method is deprecated.

boolean

This method is deprecated.

Animator
onCreateAnimator(int transit, boolean enter, int nextAnim)

This method is deprecated.

void
onCreateContextMenu(
    ContextMenu menu,
    View v,
    ContextMenu.ContextMenuInfo menuInfo
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

LayoutInflater
onGetLayoutInflater(Bundle savedInstanceState)

This method is deprecated.

void
onHiddenChanged(boolean hidden)

This method is deprecated.

void
onInflate(
    Activity activity,
    AttributeSet attrs,
    Bundle savedInstanceState
)

This method is deprecated.

void

This method is deprecated.

void
onMultiWindowModeChanged(boolean isInMultiWindowMode)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

This method is deprecated.

void

This method is deprecated.

void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)