added in version 24.1.0
belongs to Maven artifact


public final class PreferenceScreen
extends PreferenceGroup


Represents a top-level Preference that is the root of a Preference hierarchy. A PreferenceFragmentCompat points to an instance of this class to show the preferences. To instantiate this class, use createPreferenceScreen(android.content.Context).

    This class can appear in two places:
  • When a PreferenceFragmentCompat points to this, it is used as the root and is not shown (only the contained preferences are shown).
  • When it appears inside another preference hierarchy, it is shown and serves as the gateway to another screen of preferences (either by showing another screen of preferences as a Dialog or via a startActivity(android.content.Intent) from the getIntent()). The children of this PreferenceScreen are NOT shown in the screen that this PreferenceScreen is shown in. Instead, a separate screen will be shown when this preference is clicked.

Here's an example XML layout of a PreferenceScreen:

 android:key="wifi enabled"
 android:title="WiFi" />
 android:title="WiFi settings">
 android:key="prefer wifi"
 android:title="Prefer WiFi" />
 ... other preferences here ...

In this example, the "first_preferencescreen" will be used as the root of the hierarchy and given to a PreferenceFragment or PreferenceFragmentCompat. The first screen will show preferences "WiFi" (which can be used to quickly enable/disable WiFi) and "WiFi settings". The "WiFi settings" is the "second_preferencescreen" and when clicked will show another screen of preferences such as "Prefer WiFi" (and the other preferences that are children of the "second_preferencescreen" tag).

Developer Guides

For information about building a settings UI with Preferences, read the Settings guide.

See also:


Inherited XML attributes

From class
From class

Inherited constants

From class

Public methods

void setShouldUseGeneratedIds(boolean shouldUseGeneratedIds)

Set whether the adapter created for this screen should attempt to use the preference IDs generated by addPreference(Preference) as stable item IDs.

boolean shouldUseGeneratedIds()