# Preference

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:preference-v7:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v7/preference/Preference#nestedclasses)\|[XML Attrs](https://developer.android.com/reference/android/support/v7/preference/Preference#lattrs)\|[Constants](https://developer.android.com/reference/android/support/v7/preference/Preference#constants)\|[Ctors](https://developer.android.com/reference/android/support/v7/preference/Preference#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v7/preference/Preference#pubmethods)\|[Protected Methods](https://developer.android.com/reference/android/support/v7/preference/Preference#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v7/preference/Preference#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v7/preference/Preference#)  

# Preference

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
Preference
`  
`

extends Object


``


implements

Comparable<`[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)`>


`

|---|------------------------------------------|
| java.lang.Object                            ||
| ↳ | android.support.v7.preference.Preference |

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/preference/Preference#)Known Direct Subclasses [DialogPreference](https://developer.android.com/reference/android/support/v7/preference/DialogPreference),[PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup),[SeekBarPreference](https://developer.android.com/reference/android/support/v7/preference/SeekBarPreference),[TwoStatePreference](https://developer.android.com/reference/android/support/v7/preference/TwoStatePreference) |----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [DialogPreference](https://developer.android.com/reference/android/support/v7/preference/DialogPreference)     | A base class for[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)objects that are dialog-based.                                                              | | [PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)       | A container for multiple[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)objects.                                                                            | | [SeekBarPreference](https://developer.android.com/reference/android/support/v7/preference/SeekBarPreference)   | Preference based on android.preference.SeekBarPreference but uses support v7 preference as base.                                                                                                          | | [TwoStatePreference](https://developer.android.com/reference/android/support/v7/preference/TwoStatePreference) | Common base class for preferences that have two selectable states, persist a boolean value in SharedPreferences, and may have dependent preferences that are enabled/disabled based on the current state. | |

|---|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/preference/Preference#)Known Indirect Subclasses [CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference),[DropDownPreference](https://developer.android.com/reference/android/support/v7/preference/DropDownPreference),[EditTextPreference](https://developer.android.com/reference/android/support/v7/preference/EditTextPreference),[ListPreference](https://developer.android.com/reference/android/support/v7/preference/ListPreference),[MultiSelectListPreference](https://developer.android.com/reference/android/support/v14/preference/MultiSelectListPreference),[PreferenceCategory](https://developer.android.com/reference/android/support/v7/preference/PreferenceCategory),[PreferenceScreen](https://developer.android.com/reference/android/support/v7/preference/PreferenceScreen),[SwitchPreference](https://developer.android.com/reference/android/support/v14/preference/SwitchPreference),[SwitchPreferenceCompat](https://developer.android.com/reference/android/support/v7/preference/SwitchPreferenceCompat) |-------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)                | A[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that provides checkbox widget functionality.                                           | | [DropDownPreference](https://developer.android.com/reference/android/support/v7/preference/DropDownPreference)                | A version of[ListPreference](https://developer.android.com/reference/android/support/v7/preference/ListPreference)that presents the options in a drop down menu rather than a dialog. | | [EditTextPreference](https://developer.android.com/reference/android/support/v7/preference/EditTextPreference)                | A[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that allows for string input.                                                          | | [ListPreference](https://developer.android.com/reference/android/support/v7/preference/ListPreference)                        | A[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that displays a list of entries as a dialog.                                           | | [MultiSelectListPreference](https://developer.android.com/reference/android/support/v14/preference/MultiSelectListPreference) | A[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that displays a list of entries as a dialog.                                           | | [PreferenceCategory](https://developer.android.com/reference/android/support/v7/preference/PreferenceCategory)                | Used to group[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)objects and provide a disabled title above the group.                      | | [PreferenceScreen](https://developer.android.com/reference/android/support/v7/preference/PreferenceScreen)                    | Represents a top-level[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that is the root of a Preference hierarchy.                       | | [SwitchPreference](https://developer.android.com/reference/android/support/v14/preference/SwitchPreference)                   | A[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that provides a two-state toggleable option.                                           | | [SwitchPreferenceCompat](https://developer.android.com/reference/android/support/v7/preference/SwitchPreferenceCompat)        | A[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)that provides a two-state toggleable option.                                           | ||

<br />

*** ** * ** ***

Represents the basic Preference UI building block displayed by a[PreferenceFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat)in the form of a[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView). This class provides data for the[View](https://developer.android.com/reference/android/view/View.html)to be displayed in the list and associates with a[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)to store/retrieve the preference data.

When specifying a preference hierarchy in XML, each element can point to a subclass of[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference), similar to the view hierarchy and layouts.

This class contains a`key`that will be used as the key into the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html). It is up to the subclass to decide how to store the value.  

### Developer Guides

For information about building a settings UI with Preferences, read the[Settings](https://developer.android.com/guide/topics/ui/settings)guide.

<br />

## Summary

|                                                                                                                                                                                               ### Nested classes                                                                                                                                                                                               ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class`     | [Preference.BaseSavedState](https://developer.android.com/reference/android/support/v7/preference/Preference.BaseSavedState) A base class for managing the instance state of a[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference).                                                                                                                    |
| ` interface` | [Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceChangeListener) Interface definition for a callback to be invoked when the value of this[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)has been changed by the user and is about to be set and/or persisted. |
| ` interface` | [Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceClickListener) Interface definition for a callback to be invoked when a[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)is clicked.                                                                             |

|                                                                           ### XML attributes                                                                            ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [`Preference_android_iconSpaceReserved`](https://developer.android.com/reference/android/support/v7/preference/Preference#attr_Preference_android_iconSpaceReserved) |   |
| [`Preference_android_singleLineTitle`](https://developer.android.com/reference/android/support/v7/preference/Preference#attr_Preference_android_singleLineTitle)     |   |

|                                                                                                                                     ### Constants                                                                                                                                     ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [DEFAULT_ORDER](https://developer.android.com/reference/android/support/v7/preference/Preference#DEFAULT_ORDER) Specify for[setOrder(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#setOrder(int))if a specific order is not required. |

|                                                                                                                                                                                                                             ### Public constructors                                                                                                                                                                                                                              ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context, android.util.AttributeSet, int, int))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html)` attrs, int defStyleAttr, int defStyleRes) ` Perform inflation from XML and apply a class-specific base style. |
| ` `[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context, android.util.AttributeSet, int))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html)` attrs, int defStyleAttr) ` Perform inflation from XML and apply a class-specific base style.                       |
| ` `[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context, android.util.AttributeSet))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html)` attrs) ` Constructor that is called when inflating a Preference from XML.                                               |
| ` `[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context) ` Constructor to create a Preference.                                                                                                                                                                                                       |

|                                                                                                                                                                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`                                                                                                                                              | ` `[callChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference#callChangeListener(java.lang.Object))`(Object newValue) ` Call this method after the user changes the preference, but before the internal state is set.                                                                                                                                                                                                                                                                                                                                  |
| ` int`                                                                                                                                                  | ` `[compareTo](https://developer.android.com/reference/android/support/v7/preference/Preference#compareTo(android.support.v7.preference.Preference))`(`[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)` another) ` Compares Preference objects based on order (if set), otherwise alphabetically on the titles.                                                                                                                                                                                                                                    |
| ` `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                      | ` `[getContext](https://developer.android.com/reference/android/support/v7/preference/Preference#getContext())`() ` Returns the[Context](https://developer.android.com/reference/android/content/Context.html)of this Preference.                                                                                                                                                                                                                                                                                                                                                                 |
| ` String`                                                                                                                                               | ` `[getDependency](https://developer.android.com/reference/android/support/v7/preference/Preference#getDependency())`() ` Returns the key of the dependency on this Preference.                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)                                                                             | ` `[getExtras](https://developer.android.com/reference/android/support/v7/preference/Preference#getExtras())`() ` Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one.                                                                                                                                                                                                                                                                                                                                                            |
| ` String`                                                                                                                                               | ` `[getFragment](https://developer.android.com/reference/android/support/v7/preference/Preference#getFragment())`() ` Return the fragment class name associated with this Preference.                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)                                                          | ` `[getIcon](https://developer.android.com/reference/android/support/v7/preference/Preference#getIcon())`() ` Returns the icon of this Preference.                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` `[Intent](https://developer.android.com/reference/android/content/Intent.html)                                                                        | ` `[getIntent](https://developer.android.com/reference/android/support/v7/preference/Preference#getIntent())`() ` Return the[Intent](https://developer.android.com/reference/android/content/Intent.html)associated with this Preference.                                                                                                                                                                                                                                                                                                                                                         |
| ` String`                                                                                                                                               | ` `[getKey](https://developer.android.com/reference/android/support/v7/preference/Preference#getKey())`() ` Gets the key for this Preference, which is also the key used for storing values into[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)or[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore).                                                                                                                                                                            |
| ` final int`                                                                                                                                            | ` `[getLayoutResource](https://developer.android.com/reference/android/support/v7/preference/Preference#getLayoutResource())`() ` Gets the layout resource that will be shown as the[View](https://developer.android.com/reference/android/view/View.html)for this Preference.                                                                                                                                                                                                                                                                                                                    |
| ` `[Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceChangeListener) | ` `[getOnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference#getOnPreferenceChangeListener())`() ` Returns the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).                                                                                                                                                                                                                                                                                                        |
| ` `[Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceClickListener)   | ` `[getOnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference#getOnPreferenceClickListener())`() ` Returns the callback to be invoked when this Preference is clicked.                                                                                                                                                                                                                                                                                                                                                                       |
| ` int`                                                                                                                                                  | ` `[getOrder](https://developer.android.com/reference/android/support/v7/preference/Preference#getOrder())`() ` Gets the order of this Preference with respect to other Preference objects on the same level.                                                                                                                                                                                                                                                                                                                                                                                     |
| ` `[PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)                                             | ` `[getParent](https://developer.android.com/reference/android/support/v7/preference/Preference#getParent())`() ` Returns the[PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)which is this Preference assigned to or null if this preference is not assigned to any group or is a root Preference.                                                                                                                                                                                                                                        |
| ` Set<String>`                                                                                                                                          | ` `[getPersistedStringSet](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>))`(Set<String> defaultReturnValue) ` Attempts to get a persisted set of Strings if this Preference is persistent.                                                                                                                                                                                                                                                                                                               |
| ` `[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)                                     | ` `[getPreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/Preference#getPreferenceDataStore())`() ` Returns[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)used by this Preference.                                                                                                                                                                                                                                                                                                       |
| ` `[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)                                         | ` `[getPreferenceManager](https://developer.android.com/reference/android/support/v7/preference/Preference#getPreferenceManager())`() ` Gets the[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)that manages this Preference object's tree.                                                                                                                                                                                                                                                                                           |
| ` `[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)                                                  | ` `[getSharedPreferences](https://developer.android.com/reference/android/support/v7/preference/Preference#getSharedPreferences())`() ` Returns the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)where this Preference can read its value(s).                                                                                                                                                                                                                                                                                                |
| ` boolean`                                                                                                                                              | ` `[getShouldDisableView](https://developer.android.com/reference/android/support/v7/preference/Preference#getShouldDisableView())`() ` Checks whether this Preference should disable its view when it's action is disabled.                                                                                                                                                                                                                                                                                                                                                                      |
| ` CharSequence`                                                                                                                                         | ` `[getSummary](https://developer.android.com/reference/android/support/v7/preference/Preference#getSummary())`() ` Returns the summary of this Preference.                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` CharSequence`                                                                                                                                         | ` `[getTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#getTitle())`() ` Returns the title of this Preference.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` final int`                                                                                                                                            | ` `[getWidgetLayoutResource](https://developer.android.com/reference/android/support/v7/preference/Preference#getWidgetLayoutResource())`() ` Gets the layout resource for the controllable widget portion of this Preference.                                                                                                                                                                                                                                                                                                                                                                    |
| ` boolean`                                                                                                                                              | ` `[hasKey](https://developer.android.com/reference/android/support/v7/preference/Preference#hasKey())`() ` Checks whether this Preference has a valid key.                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` boolean`                                                                                                                                              | ` `[isEnabled](https://developer.android.com/reference/android/support/v7/preference/Preference#isEnabled())`() ` Checks whether this Preference should be enabled in the list.                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` boolean`                                                                                                                                              | ` `[isIconSpaceReserved](https://developer.android.com/reference/android/support/v7/preference/Preference#isIconSpaceReserved())`() ` Returns whether the space of this preference icon view is reserved.                                                                                                                                                                                                                                                                                                                                                                                         |
| ` boolean`                                                                                                                                              | ` `[isPersistent](https://developer.android.com/reference/android/support/v7/preference/Preference#isPersistent())`() ` Checks whether this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` boolean`                                                                                                                                              | ` `[isSelectable](https://developer.android.com/reference/android/support/v7/preference/Preference#isSelectable())`() ` Checks whether this Preference should be selectable in the list.                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` boolean`                                                                                                                                              | ` `[isSingleLineTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#isSingleLineTitle())`() ` Gets whether the title of this preference is constrained to a single line.                                                                                                                                                                                                                                                                                                                                                                                      |
| ` final boolean`                                                                                                                                        | ` `[isVisible](https://developer.android.com/reference/android/support/v7/preference/Preference#isVisible())`() ` Checks whether this preference should be visible to the user in the list.                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                                                 | ` `[notifyDependencyChange](https://developer.android.com/reference/android/support/v7/preference/Preference#notifyDependencyChange(boolean))`(boolean disableDependents) ` Notifies any listening dependents of a change that affects the dependency.                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                                                                 | ` `[onAttached](https://developer.android.com/reference/android/support/v7/preference/Preference#onAttached())`() ` Called when the Preference hierarchy has been attached to the list of preferences.                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                                                                 | ` `[onBindViewHolder](https://developer.android.com/reference/android/support/v7/preference/Preference#onBindViewHolder(android.support.v7.preference.PreferenceViewHolder))`(`[PreferenceViewHolder](https://developer.android.com/reference/android/support/v7/preference/PreferenceViewHolder)` holder) ` Binds the created View to the data for this Preference.                                                                                                                                                                                                                              |
| ` void`                                                                                                                                                 | ` `[onDependencyChanged](https://developer.android.com/reference/android/support/v7/preference/Preference#onDependencyChanged(android.support.v7.preference.Preference, boolean))`(`[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)` dependency, boolean disableDependent) ` Called when the dependency changes.                                                                                                                                                                                                                                   |
| ` void`                                                                                                                                                 | ` `[onDetached](https://developer.android.com/reference/android/support/v7/preference/Preference#onDetached())`() ` Called when the Preference hierarchy has been detached from the list of preferences.                                                                                                                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                                                                 | ` `[onInitializeAccessibilityNodeInfo](https://developer.android.com/reference/android/support/v7/preference/Preference#onInitializeAccessibilityNodeInfo(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat))`(`[AccessibilityNodeInfoCompat](https://developer.android.com/reference/android/support/v4/view/accessibility/AccessibilityNodeInfoCompat)` info) ` Initializes an[AccessibilityNodeInfo](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html)with information about the View for this Preference.                        |
| ` void`                                                                                                                                                 | ` `[onParentChanged](https://developer.android.com/reference/android/support/v7/preference/Preference#onParentChanged(android.support.v7.preference.Preference, boolean))`(`[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)` parent, boolean disableChild) ` Called when the implicit parent dependency changes.                                                                                                                                                                                                                                   |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)                                                                             | ` `[peekExtras](https://developer.android.com/reference/android/support/v7/preference/Preference#peekExtras())`() ` Return the extras Bundle object associated with this preference, returning null if there is not currently one.                                                                                                                                                                                                                                                                                                                                                                |
| ` boolean`                                                                                                                                              | ` `[persistStringSet](https://developer.android.com/reference/android/support/v7/preference/Preference#persistStringSet(java.util.Set<java.lang.String>))`(Set<String> values) ` Attempts to persist a set of Strings if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                                                 | ` `[restoreHierarchyState](https://developer.android.com/reference/android/support/v7/preference/Preference#restoreHierarchyState(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` container) ` Restore this Preference hierarchy's previously saved state from the given container.                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                                 | ` `[saveHierarchyState](https://developer.android.com/reference/android/support/v7/preference/Preference#saveHierarchyState(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` container) ` Store this Preference hierarchy's frozen state into the given container.                                                                                                                                                                                                                                                                                 |
| ` void`                                                                                                                                                 | ` `[setDefaultValue](https://developer.android.com/reference/android/support/v7/preference/Preference#setDefaultValue(java.lang.Object))`(Object defaultValue) ` Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage.                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                                                 | ` `[setDependency](https://developer.android.com/reference/android/support/v7/preference/Preference#setDependency(java.lang.String))`(String dependencyKey) ` Sets the key of a Preference that this Preference will depend on.                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                                                                                                 | ` `[setEnabled](https://developer.android.com/reference/android/support/v7/preference/Preference#setEnabled(boolean))`(boolean enabled) ` Sets whether this Preference is enabled.                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                                                                 | ` `[setFragment](https://developer.android.com/reference/android/support/v7/preference/Preference#setFragment(java.lang.String))`(String fragment) ` Sets the class name of a fragment to be shown when this Preference is clicked.                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                                 | ` `[setIcon](https://developer.android.com/reference/android/support/v7/preference/Preference#setIcon(android.graphics.drawable.Drawable))`(`[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)` icon) ` Sets the icon for this Preference with a Drawable.                                                                                                                                                                                                                                                                                              |
| ` void`                                                                                                                                                 | ` `[setIcon](https://developer.android.com/reference/android/support/v7/preference/Preference#setIcon(int))`(int iconResId) ` Sets the icon for this Preference with a resource ID.                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                                 | ` `[setIconSpaceReserved](https://developer.android.com/reference/android/support/v7/preference/Preference#setIconSpaceReserved(boolean))`(boolean iconSpaceReserved) ` Sets whether to reserve the space of this Preference icon view when no icon is provided.                                                                                                                                                                                                                                                                                                                                  |
| ` void`                                                                                                                                                 | ` `[setIntent](https://developer.android.com/reference/android/support/v7/preference/Preference#setIntent(android.content.Intent))`(`[Intent](https://developer.android.com/reference/android/content/Intent.html)` intent) ` Sets an[Intent](https://developer.android.com/reference/android/content/Intent.html)to be used for[startActivity(Intent)](https://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent))when this Preference is clicked.                                                                                               |
| ` void`                                                                                                                                                 | ` `[setKey](https://developer.android.com/reference/android/support/v7/preference/Preference#setKey(java.lang.String))`(String key) ` Sets the key for this Preference, which is used as a key to the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)or[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore).                                                                                                                                                                       |
| ` void`                                                                                                                                                 | ` `[setLayoutResource](https://developer.android.com/reference/android/support/v7/preference/Preference#setLayoutResource(int))`(int layoutResId) ` Sets the layout resource that is inflated as the[View](https://developer.android.com/reference/android/view/View.html)to be shown for this Preference.                                                                                                                                                                                                                                                                                        |
| ` void`                                                                                                                                                 | ` `[setOnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference#setOnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener))`(`[Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceChangeListener)` onPreferenceChangeListener) ` Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).                                                       |
| ` void`                                                                                                                                                 | ` `[setOnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference#setOnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener))`(`[Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceClickListener)` onPreferenceClickListener) ` Sets the callback to be invoked when this Preference is clicked.                                                                                                                          |
| ` void`                                                                                                                                                 | ` `[setOrder](https://developer.android.com/reference/android/support/v7/preference/Preference#setOrder(int))`(int order) ` Sets the order of this Preference with respect to other Preference objects on the same level.                                                                                                                                                                                                                                                                                                                                                                         |
| ` void`                                                                                                                                                 | ` `[setPersistent](https://developer.android.com/reference/android/support/v7/preference/Preference#setPersistent(boolean))`(boolean persistent) ` Sets whether this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                                                 | ` `[setPreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/Preference#setPreferenceDataStore(android.support.v7.preference.PreferenceDataStore))`(`[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)` dataStore) ` Sets a[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)to be used by this Preference instead of using[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html). |
| ` void`                                                                                                                                                 | ` `[setSelectable](https://developer.android.com/reference/android/support/v7/preference/Preference#setSelectable(boolean))`(boolean selectable) ` Sets whether this Preference is selectable.                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                                                 | ` `[setShouldDisableView](https://developer.android.com/reference/android/support/v7/preference/Preference#setShouldDisableView(boolean))`(boolean shouldDisableView) ` Sets whether this Preference should disable its view when it gets disabled.                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                                 | ` `[setSingleLineTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#setSingleLineTitle(boolean))`(boolean singleLineTitle) ` Sets whether to constrain the title of this Preference to a single line instead of letting it wrap onto multiple lines.                                                                                                                                                                                                                                                                                                         |
| ` void`                                                                                                                                                 | ` `[setSummary](https://developer.android.com/reference/android/support/v7/preference/Preference#setSummary(java.lang.CharSequence))`(CharSequence summary) ` Sets the summary for this Preference with a CharSequence.                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                                                 | ` `[setSummary](https://developer.android.com/reference/android/support/v7/preference/Preference#setSummary(int))`(int summaryResId) ` Sets the summary for this Preference with a resource ID.                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                                                                                                 | ` `[setTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#setTitle(java.lang.CharSequence))`(CharSequence title) ` Sets the title for this Preference with a CharSequence.                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                                                                                                 | ` `[setTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#setTitle(int))`(int titleResId) ` Sets the title for this Preference with a resource ID.                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                                                 | ` `[setViewId](https://developer.android.com/reference/android/support/v7/preference/Preference#setViewId(int))`(int viewId) ` Set the ID that will be assigned to the overall View representing this preference, once bound.                                                                                                                                                                                                                                                                                                                                                                     |
| ` final void`                                                                                                                                           | ` `[setVisible](https://developer.android.com/reference/android/support/v7/preference/Preference#setVisible(boolean))`(boolean visible) ` Sets whether this preference should be visible in the list.                                                                                                                                                                                                                                                                                                                                                                                             |
| ` void`                                                                                                                                                 | ` `[setWidgetLayoutResource](https://developer.android.com/reference/android/support/v7/preference/Preference#setWidgetLayoutResource(int))`(int widgetLayoutResId) ` Sets the layout for the controllable widget portion of this Preference.                                                                                                                                                                                                                                                                                                                                                     |
| ` boolean`                                                                                                                                              | ` `[shouldDisableDependents](https://developer.android.com/reference/android/support/v7/preference/Preference#shouldDisableDependents())`() ` Checks whether this preference's dependents should currently be disabled.                                                                                                                                                                                                                                                                                                                                                                           |
| ` String`                                                                                                                                               | ` `[toString](https://developer.android.com/reference/android/support/v7/preference/Preference#toString())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

|                                                                                                                                                                                                                                                                                              ### Protected methods                                                                                                                                                                                                                                                                                              ||
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference) | ` `[findPreferenceInHierarchy](https://developer.android.com/reference/android/support/v7/preference/Preference#findPreferenceInHierarchy(java.lang.String))`(String key) ` Finds a Preference in this hierarchy (the whole thing, even above/below your[PreferenceScreen](https://developer.android.com/reference/android/support/v7/preference/PreferenceScreen)screen break) with the given key.                                                                                                          |
| ` boolean`                                                                                        | ` `[getPersistedBoolean](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedBoolean(boolean))`(boolean defaultReturnValue) ` Attempts to get a persisted[Boolean](https://developer.android.com/reference/java/lang/Boolean)if this Preference is persistent.                                                                                                                                                                                                      |
| ` float`                                                                                          | ` `[getPersistedFloat](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedFloat(float))`(float defaultReturnValue) ` Attempts to get a persisted[Float](https://developer.android.com/reference/java/lang/Float)if this Preference is persistent.                                                                                                                                                                                                                  |
| ` int`                                                                                            | ` `[getPersistedInt](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedInt(int))`(int defaultReturnValue) ` Attempts to get a persisted[Integer](https://developer.android.com/reference/java/lang/Integer)if this Preference is persistent.                                                                                                                                                                                                                      |
| ` long`                                                                                           | ` `[getPersistedLong](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedLong(long))`(long defaultReturnValue) ` Attempts to get a persisted[Long](https://developer.android.com/reference/java/lang/Long)if this Preference is persistent.                                                                                                                                                                                                                        |
| ` String`                                                                                         | ` `[getPersistedString](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String))`(String defaultReturnValue) ` Attempts to get a persisted set of Strings if this Preference is persistent.                                                                                                                                                                                                                                                    |
| ` void`                                                                                           | ` `[notifyChanged](https://developer.android.com/reference/android/support/v7/preference/Preference#notifyChanged())`() ` Should be called when the data of this[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)has changed.                                                                                                                                                                                                                                   |
| ` void`                                                                                           | ` `[notifyHierarchyChanged](https://developer.android.com/reference/android/support/v7/preference/Preference#notifyHierarchyChanged())`() ` Should be called when a Preference has been added/removed from this group, or the ordering should be re-evaluated.                                                                                                                                                                                                                                               |
| ` void`                                                                                           | ` `[onAttachedToHierarchy](https://developer.android.com/reference/android/support/v7/preference/Preference#onAttachedToHierarchy(android.support.v7.preference.PreferenceManager))`(`[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)` preferenceManager) ` Called when this Preference has been attached to a Preference hierarchy.                                                                                                            |
| ` void`                                                                                           | ` `[onClick](https://developer.android.com/reference/android/support/v7/preference/Preference#onClick())`() ` Processes a click on the preference.                                                                                                                                                                                                                                                                                                                                                           |
| ` Object`                                                                                         | ` `[onGetDefaultValue](https://developer.android.com/reference/android/support/v7/preference/Preference#onGetDefaultValue(android.content.res.TypedArray, int))`(`[TypedArray](https://developer.android.com/reference/android/content/res/TypedArray.html)` a, int index) ` Called when a Preference is being inflated and the default value attribute needs to be read.                                                                                                                                    |
| ` void`                                                                                           | ` `[onPrepareForRemoval](https://developer.android.com/reference/android/support/v7/preference/Preference#onPrepareForRemoval())`() ` Called when this Preference is being removed from the hierarchy.                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                           | ` `[onRestoreInstanceState](https://developer.android.com/reference/android/support/v7/preference/Preference#onRestoreInstanceState(android.os.Parcelable))`(`[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)` state) ` Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by[onSaveInstanceState()](https://developer.android.com/reference/android/support/v7/preference/Preference#onSaveInstanceState()). |
| ` `[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)               | ` `[onSaveInstanceState](https://developer.android.com/reference/android/support/v7/preference/Preference#onSaveInstanceState())`() ` Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state.                                                                                                                                                                                                                    |
| ` void`                                                                                           | ` `[onSetInitialValue](https://developer.android.com/reference/android/support/v7/preference/Preference#onSetInitialValue(boolean, java.lang.Object))`(boolean restorePersistedValue, Object defaultValue) ` Implement this to set the initial value of the Preference.                                                                                                                                                                                                                                      |
| ` boolean`                                                                                        | ` `[persistBoolean](https://developer.android.com/reference/android/support/v7/preference/Preference#persistBoolean(boolean))`(boolean value) ` Attempts to persist a[Boolean](https://developer.android.com/reference/java/lang/Boolean)if this Preference is persistent.                                                                                                                                                                                                                                   |
| ` boolean`                                                                                        | ` `[persistFloat](https://developer.android.com/reference/android/support/v7/preference/Preference#persistFloat(float))`(float value) ` Attempts to persist a[Float](https://developer.android.com/reference/java/lang/Float)if this Preference is persistent.                                                                                                                                                                                                                                               |
| ` boolean`                                                                                        | ` `[persistInt](https://developer.android.com/reference/android/support/v7/preference/Preference#persistInt(int))`(int value) ` Attempts to persist an[Integer](https://developer.android.com/reference/java/lang/Integer)if this Preference is persistent.                                                                                                                                                                                                                                                  |
| ` boolean`                                                                                        | ` `[persistLong](https://developer.android.com/reference/android/support/v7/preference/Preference#persistLong(long))`(long value) ` Attempts to persist a[Long](https://developer.android.com/reference/java/lang/Long)if this Preference is persistent.                                                                                                                                                                                                                                                     |
| ` boolean`                                                                                        | ` `[persistString](https://developer.android.com/reference/android/support/v7/preference/Preference#persistString(java.lang.String))`(String value) ` Attempts to persist a[String](https://developer.android.com/reference/java/lang/String)if this Preference is persistent.                                                                                                                                                                                                                               |
| ` boolean`                                                                                        | ` `[shouldPersist](https://developer.android.com/reference/android/support/v7/preference/Preference#shouldPersist())`() ` Checks whether, at the given time this method is called, this Preference should store/restore its value(s) into the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)or into[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)if assigned.                          |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/preference/Preference#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/preference/Preference#)From interface` java.lang.Comparable ` |-----------------|----------------------------------------------------------------------------------------------------------------------| | ` abstract int` | ` compareTo(`[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)` arg0) ` | ||

## XML attributes

### Preference_android_iconSpaceReserved

<br />

<br />

**Related methods:**

- [setIconSpaceReserved(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setIconSpaceReserved(boolean))

### Preference_android_singleLineTitle

<br />

<br />

**Related methods:**

- [setSingleLineTitle(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setSingleLineTitle(boolean))

## Constants

### DEFAULT_ORDER

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int DEFAULT_ORDER
```

Specify for[setOrder(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#setOrder(int))if a specific order is not required.

<br />

Constant Value: 2147483647 (0x7fffffff)

## Public constructors

### Preference

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)
```

Perform inflation from XML and apply a class-specific base style. This constructor of Preference allows subclasses to use their own base style when they are inflating. For example, a[CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)constructor calls this version of the super class constructor and supplies`android.R.attr.checkBoxPreferenceStyle`for<var translate="no">defStyleAttr</var>. This allows the theme's checkbox preference style to modify all of the base preference attributes as well as the[CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)class's attributes.

<br />

|                                                                                                                Parameters                                                                                                                 ||
|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`      | `Context`: The Context this is associated with, through which it can access the current theme, resources,[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html), etc. <br /> |
| `attrs`        | `AttributeSet`: The attributes of the XML tag that is inflating the preference. <br />                                                                                                                                    |
| `defStyleAttr` | `int`: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults. <br />                                               |
| `defStyleRes`  | `int`: A resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults. <br />                    |

**See also:**

- [Preference(Context, android.util.AttributeSet)](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context, android.util.AttributeSet))  

### Preference

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)
```

Perform inflation from XML and apply a class-specific base style. This constructor of Preference allows subclasses to use their own base style when they are inflating. For example, a[CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)constructor calls this version of the super class constructor and supplies`android.R.attr.checkBoxPreferenceStyle`for<var translate="no">defStyleAttr</var>. This allows the theme's checkbox preference style to modify all of the base preference attributes as well as the[CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)class's attributes.

<br />

|                                                                                                                Parameters                                                                                                                 ||
|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`      | `Context`: The Context this is associated with, through which it can access the current theme, resources,[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html), etc. <br /> |
| `attrs`        | `AttributeSet`: The attributes of the XML tag that is inflating the preference. <br />                                                                                                                                    |
| `defStyleAttr` | `int`: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults. <br />                                               |

**See also:**

- [Preference(Context, AttributeSet)](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context, android.util.AttributeSet))  

### Preference

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference (Context context, 
                AttributeSet attrs)
```

Constructor that is called when inflating a Preference from XML. This is called when a Preference is being constructed from an XML file, supplying attributes that were specified in the XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context's Theme and the given AttributeSet.

<br />

|                                                                                                              Parameters                                                                                                              ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context` | `Context`: The Context this is associated with, through which it can access the current theme, resources,[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html), etc. <br /> |
| `attrs`   | `AttributeSet`: The attributes of the XML tag that is inflating the preference. <br />                                                                                                                                    |

**See also:**

- [Preference(Context, AttributeSet, int)](https://developer.android.com/reference/android/support/v7/preference/Preference#Preference(android.content.Context, android.util.AttributeSet, int))  

### Preference

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference (Context context)
```

Constructor to create a Preference.

<br />

|                                  Parameters                                   ||
|-----------|--------------------------------------------------------------------|
| `context` | `Context`: The Context in which to store Preference values. <br /> |

## Public methods

### callChangeListener

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean callChangeListener (Object newValue)
```

Call this method after the user changes the preference, but before the internal state is set. This allows the client to ignore the user value.

<br />

|                           Parameters                           ||
|------------|----------------------------------------------------|
| `newValue` | `Object`: The new value of this Preference. <br /> |

|                                             Returns                                             ||
|-----------|--------------------------------------------------------------------------------------|
| `boolean` | True if the user value should be set as the preference value (and persisted). <br /> |

### compareTo

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int compareTo (Preference another)
```

Compares Preference objects based on order (if set), otherwise alphabetically on the titles.

<br />

|                               Parameters                               ||
|-----------|-------------------------------------------------------------|
| `another` | `Preference`: The Preference to compare to this one. <br /> |

|                                                                                           Returns                                                                                            ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | 0 if the same; less than 0 if this Preference sorts ahead of<var translate="no">another</var>; greater than 0 if this Preference sorts after<var translate="no">another</var>. <br /> |

### getContext

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Context getContext ()
```

Returns the[Context](https://developer.android.com/reference/android/content/Context.html)of this Preference. Each Preference in a Preference hierarchy can be from different Context (for example, if multiple activities provide preferences into a single[PreferenceFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat)). This Context will be used to save the Preference values.

<br />

|                                                         Returns                                                         ||
|---------------------------------------------------------------------------------|----------------------------------------|
| [Context](https://developer.android.com/reference/android/content/Context.html) | The Context of this Preference. <br /> |

### getDependency

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getDependency ()
```

Returns the key of the dependency on this Preference.

<br />

|                   Returns                   ||
|----------|-----------------------------------|
| `String` | The key of the dependency. <br /> |

**See also:**

- [setDependency(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#setDependency(java.lang.String))  

### getExtras

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Bundle getExtras ()
```

Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one. You can use this to get and set individual extra key/value pairs.

<br />

|                                     Returns                                      ||
|--------------------------------------------------------------------------|--------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html) | <br /> |

### getFragment

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getFragment ()
```

Return the fragment class name associated with this Preference.

<br />

|                                                                                              Returns                                                                                              ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `String` | The fragment class name last set via[setFragment(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#setFragment(java.lang.String))or XML. <br /> |

### getIcon

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Drawable getIcon ()
```

Returns the icon of this Preference.

<br />

|                                                    Returns                                                    ||
|---------------------------------------------------------------------------------------------|------------------|
| [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) | The icon. <br /> |

**See also:**

- [setIcon(Drawable)](https://developer.android.com/reference/android/support/v7/preference/Preference#setIcon(android.graphics.drawable.Drawable))  

### getIntent

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Intent getIntent ()
```

Return the[Intent](https://developer.android.com/reference/android/content/Intent.html)associated with this Preference.

<br />

|                                                                                                                                                             Returns                                                                                                                                                              ||
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Intent](https://developer.android.com/reference/android/content/Intent.html) | The[Intent](https://developer.android.com/reference/android/content/Intent.html)last set via[setIntent(Intent)](https://developer.android.com/reference/android/support/v7/preference/Preference#setIntent(android.content.Intent))or XML. <br /> |

### getKey

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getKey ()
```

Gets the key for this Preference, which is also the key used for storing values into[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)or[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore).

<br />

|          Returns          ||
|----------|-----------------|
| `String` | The key. <br /> |

### getLayoutResource

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getLayoutResource ()
```

Gets the layout resource that will be shown as the[View](https://developer.android.com/reference/android/view/View.html)for this Preference.

<br />

|                Returns                ||
|-------|--------------------------------|
| `int` | The layout resource ID. <br /> |

### getOnPreferenceChangeListener

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference.OnPreferenceChangeListener getOnPreferenceChangeListener ()
```

Returns the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).

<br />

|                                                                                         Returns                                                                                          ||
|------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| [Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceChangeListener) | The callback to be invoked. <br /> |

### getOnPreferenceClickListener

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference.OnPreferenceClickListener getOnPreferenceClickListener ()
```

Returns the callback to be invoked when this Preference is clicked.

<br />

|                                                                                        Returns                                                                                         ||
|----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| [Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceClickListener) | The callback to be invoked. <br /> |

### getOrder

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getOrder ()
```

Gets the order of this Preference with respect to other Preference objects on the same level.

<br />

|                   Returns                   ||
|-------|--------------------------------------|
| `int` | The order of this Preference. <br /> |

**See also:**

- [setOrder(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#setOrder(int))  

### getParent

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
PreferenceGroup getParent ()
```

Returns the[PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)which is this Preference assigned to or null if this preference is not assigned to any group or is a root Preference.

<br />

|                                                                                   Returns                                                                                   ||
|----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup) | The parent PreferenceGroup or null if not attached to any. <br /> |

### getPersistedStringSet

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Set<String> getPersistedStringSet (Set<String> defaultReturnValue)
```

Attempts to get a persisted set of Strings if this Preference is persistent.

<br />

|                                                                  Parameters                                                                   ||
|----------------------|-------------------------------------------------------------------------------------------------------------------------|
| `defaultReturnValue` | `Set`: the default value to return if either this Preference is not persistent or this Preference is not present <br /> |

|                                   Returns                                    ||
|---------------|---------------------------------------------------------------|
| `Set<String>` | the value from the storage or the default return value <br /> |

**See also:**

- [persistStringSet(Set)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistStringSet(java.util.Set<java.lang.String>))  

### getPreferenceDataStore

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
PreferenceDataStore getPreferenceDataStore ()
```

Returns[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)used by this Preference. Returns`null`if[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)is used instead.

By default preferences always use[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html). To make this preference to use the[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)you need to assign your implementation to the Preference itself via[setPreferenceDataStore(PreferenceDataStore)](https://developer.android.com/reference/android/support/v7/preference/Preference#setPreferenceDataStore(android.support.v7.preference.PreferenceDataStore))or to its[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)via[setPreferenceDataStore(PreferenceDataStore)](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager#setPreferenceDataStore(android.support.v7.preference.PreferenceDataStore)).

<br />

|                                                                                                                                       Returns                                                                                                                                       ||
|------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore) | the[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)used by this Preference or`null`if none <br /> |

### getPreferenceManager

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
PreferenceManager getPreferenceManager ()
```

Gets the[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)that manages this Preference object's tree.

<br />

|                                                                                                                Returns                                                                                                                ||
|--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager) | The[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager). <br /> |

### getSharedPreferences

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
SharedPreferences getSharedPreferences ()
```

Returns the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)where this Preference can read its value(s). Usually, it's easier to use one of the helper read methods:[getPersistedBoolean(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedBoolean(boolean)),[getPersistedFloat(float)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedFloat(float)),[getPersistedInt(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedInt(int)),[getPersistedLong(long)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedLong(long)),[getPersistedString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String)).

<br />

|                                                                                                                                                                                                                                         Returns                                                                                                                                                                                                                                          ||
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html) | the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)where this Preference reads its value(s). If this preference is not attached to a Preference hierarchy or if a[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)has been set, this method returns`null`. <br /> |

**See also:**

- [setPreferenceDataStore(PreferenceDataStore)](https://developer.android.com/reference/android/support/v7/preference/Preference#setPreferenceDataStore(android.support.v7.preference.PreferenceDataStore))  

### getShouldDisableView

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean getShouldDisableView ()
```

Checks whether this Preference should disable its view when it's action is disabled.

<br />

|                        Returns                        ||
|-----------|--------------------------------------------|
| `boolean` | True if it should disable the view. <br /> |

**See also:**

- [setShouldDisableView(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setShouldDisableView(boolean))  

### getSummary

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
CharSequence getSummary ()
```

Returns the summary of this Preference.

<br />

|               Returns               ||
|----------------|---------------------|
| `CharSequence` | The summary. <br /> |

**See also:**

- [setSummary(CharSequence)](https://developer.android.com/reference/android/support/v7/preference/Preference#setSummary(java.lang.CharSequence))  

### getTitle

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
CharSequence getTitle ()
```

Returns the title of this Preference.

<br />

|              Returns              ||
|----------------|-------------------|
| `CharSequence` | The title. <br /> |

**See also:**

- [setTitle(CharSequence)](https://developer.android.com/reference/android/support/v7/preference/Preference#setTitle(java.lang.CharSequence))  

### getWidgetLayoutResource

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getWidgetLayoutResource ()
```

Gets the layout resource for the controllable widget portion of this Preference.

<br />

|                Returns                ||
|-------|--------------------------------|
| `int` | The layout resource ID. <br /> |

### hasKey

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean hasKey ()
```

Checks whether this Preference has a valid key.

<br />

|                                       Returns                                        ||
|-----------|---------------------------------------------------------------------------|
| `boolean` | True if the key exists and is not a blank string, false otherwise. <br /> |

### isEnabled

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isEnabled ()
```

Checks whether this Preference should be enabled in the list.

<br />

|                                Returns                                 ||
|-----------|-------------------------------------------------------------|
| `boolean` | True if this Preference is enabled, false otherwise. <br /> |

### isIconSpaceReserved

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isIconSpaceReserved ()
```

Returns whether the space of this preference icon view is reserved.

<br />

**Related XML Attributes:**

- [Preference_android_iconSpaceReserved](https://developer.android.com/reference/android/support/v7/preference/Preference#attr_Preference_android_iconSpaceReserved)

|                                    Returns                                    ||
|-----------|--------------------------------------------------------------------|
| `boolean` | `true`if the space of this preference icon view is reserved <br /> |

**See also:**

- [setIconSpaceReserved(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setIconSpaceReserved(boolean))  

### isPersistent

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isPersistent ()
```

Checks whether this Preference is persistent. If it is, it stores its value(s) into the persistent[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)storage by default or into[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)if assigned.

<br />

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if persistent <br /> |

### isSelectable

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isSelectable ()
```

Checks whether this Preference should be selectable in the list.

<br />

|                           Returns                            ||
|-----------|---------------------------------------------------|
| `boolean` | True if it is selectable, false otherwise. <br /> |

### isSingleLineTitle

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isSingleLineTitle ()
```

Gets whether the title of this preference is constrained to a single line.

<br />

**Related XML Attributes:**

- [Preference_android_singleLineTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#attr_Preference_android_singleLineTitle)

|                                         Returns                                         ||
|-----------|------------------------------------------------------------------------------|
| `boolean` | `true`if the title of this preference is constrained to a single line <br /> |

**See also:**

- [setSingleLineTitle(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setSingleLineTitle(boolean))  

### isVisible

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isVisible ()
```

Checks whether this preference should be visible to the user in the list.

<br />

|                            Returns                             ||
|-----------|-----------------------------------------------------|
| `boolean` | True if this preference should be displayed. <br /> |

**See also:**

- [setVisible(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setVisible(boolean))  

### notifyDependencyChange

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void notifyDependencyChange (boolean disableDependents)
```

Notifies any listening dependents of a change that affects the dependency.

<br />

|                                          Parameters                                           ||
|---------------------|--------------------------------------------------------------------------|
| `disableDependents` | `boolean`: Whether this Preference should disable its dependents. <br /> |

### onAttached

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onAttached ()
```

Called when the Preference hierarchy has been attached to the list of preferences. This can also be called when this Preference has been attached to a group that was already attached to the list of preferences.

<br />

### onBindViewHolder

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onBindViewHolder (PreferenceViewHolder holder)
```

Binds the created View to the data for this Preference.

This is a good place to grab references to custom Views in the layout and set properties on them.

Make sure to call through to the superclass's implementation.

<br />

|                                                                                                  Parameters                                                                                                   ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `holder` | `PreferenceViewHolder`: The ViewHolder that provides references to the views to fill in. These views will be recycled, so you should not hold a reference to them after this method returns. <br /> |

### onDependencyChanged

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onDependencyChanged (Preference dependency, 
                boolean disableDependent)
```

Called when the dependency changes.

<br />

|                                        Parameters                                        ||
|--------------------|----------------------------------------------------------------------|
| `dependency`       | `Preference`: The Preference that this Preference depends on. <br /> |
| `disableDependent` | `boolean`: Set true to disable this Preference. <br />               |

### onDetached

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onDetached ()
```

Called when the Preference hierarchy has been detached from the list of preferences. This can also be called when this Preference has been removed from a group that was attached to the list of preferences.

<br />

### onInitializeAccessibilityNodeInfo

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfoCompat info)
```

Initializes an[AccessibilityNodeInfo](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html)with information about the View for this Preference.

<br />

|                  Parameters                  ||
|--------|--------------------------------------|
| `info` | `AccessibilityNodeInfoCompat` <br /> |

### onParentChanged

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onParentChanged (Preference parent, 
                boolean disableChild)
```

Called when the implicit parent dependency changes.

<br />

|                                      Parameters                                      ||
|----------------|----------------------------------------------------------------------|
| `parent`       | `Preference`: The Preference that this Preference depends on. <br /> |
| `disableChild` | `boolean`: Set true to disable this Preference. <br />               |

### peekExtras

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Bundle peekExtras ()
```

Return the extras Bundle object associated with this preference, returning null if there is not currently one.

<br />

|                                     Returns                                      ||
|--------------------------------------------------------------------------|--------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html) | <br /> |

### persistStringSet

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean persistStringSet (Set<String> values)
```

Attempts to persist a set of Strings if this Preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

<br />

|                  Parameters                   ||
|----------|-------------------------------------|
| `values` | `Set`: the values to persist <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | `true`if the Preference is persistent,`false`otherwise <br /> |

**See also:**

- [getPersistedStringSet(Set)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>))  

### restoreHierarchyState

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void restoreHierarchyState (Bundle container)
```

Restore this Preference hierarchy's previously saved state from the given container.

<br />

|                                   Parameters                                    ||
|-------------|--------------------------------------------------------------------|
| `container` | `Bundle`: The Bundle that holds the previously saved state. <br /> |

**See also:**

- [saveHierarchyState(Bundle)](https://developer.android.com/reference/android/support/v7/preference/Preference#saveHierarchyState(android.os.Bundle))
- [onRestoreInstanceState(Parcelable)](https://developer.android.com/reference/android/support/v7/preference/Preference#onRestoreInstanceState(android.os.Parcelable))  

### saveHierarchyState

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void saveHierarchyState (Bundle container)
```

Store this Preference hierarchy's frozen state into the given container.

<br />

|                                         Parameters                                         ||
|-------------|-------------------------------------------------------------------------------|
| `container` | `Bundle`: The Bundle in which to save the instance of this Preference. <br /> |

**See also:**

- [restoreHierarchyState(Bundle)](https://developer.android.com/reference/android/support/v7/preference/Preference#restoreHierarchyState(android.os.Bundle))
- [onSaveInstanceState()](https://developer.android.com/reference/android/support/v7/preference/Preference#onSaveInstanceState())  

### setDefaultValue

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setDefaultValue (Object defaultValue)
```

Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage.

<br />

|                     Parameters                      ||
|----------------|-------------------------------------|
| `defaultValue` | `Object`: The default value. <br /> |

### setDependency

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setDependency (String dependencyKey)
```

Sets the key of a Preference that this Preference will depend on. If that Preference is not set or is off, this Preference will be disabled.

<br />

|                                    Parameters                                     ||
|-----------------|------------------------------------------------------------------|
| `dependencyKey` | `String`: The key of the Preference that this depends on. <br /> |

### setEnabled

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setEnabled (boolean enabled)
```

Sets whether this Preference is enabled. If disabled, it will not handle clicks.

<br />

|                     Parameters                      ||
|-----------|------------------------------------------|
| `enabled` | `boolean`: Set true to enable it. <br /> |

### setFragment

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setFragment (String fragment)
```

Sets the class name of a fragment to be shown when this Preference is clicked.

<br />

|                                          Parameters                                          ||
|------------|----------------------------------------------------------------------------------|
| `fragment` | `String`: The class name of the fragment associated with this Preference. <br /> |

### setIcon

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setIcon (Drawable icon)
```

Sets the icon for this Preference with a Drawable. This icon will be placed into the ID[icon](https://developer.android.com/reference/android/R.id#icon)within the View created by[onBindViewHolder(PreferenceViewHolder)](https://developer.android.com/reference/android/support/v7/preference/Preference#onBindViewHolder(android.support.v7.preference.PreferenceViewHolder)).

<br />

|                            Parameters                             ||
|--------|-----------------------------------------------------------|
| `icon` | `Drawable`: The optional icon for this Preference. <br /> |

### setIcon

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setIcon (int iconResId)
```

Sets the icon for this Preference with a resource ID.

<br />

|                      Parameters                       ||
|-------------|------------------------------------------|
| `iconResId` | `int`: The icon as a resource ID. <br /> |

**See also:**

- [setIcon(Drawable)](https://developer.android.com/reference/android/support/v7/preference/Preference#setIcon(android.graphics.drawable.Drawable))  

### setIconSpaceReserved

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setIconSpaceReserved (boolean iconSpaceReserved)
```

Sets whether to reserve the space of this Preference icon view when no icon is provided. If set to true, the preference will be offset as if it would have the icon and thus aligned with other preferences having icons.

<br />

**Related XML Attributes:**

- [Preference_android_iconSpaceReserved](https://developer.android.com/reference/android/support/v7/preference/Preference#attr_Preference_android_iconSpaceReserved)

|                                            Parameters                                             ||
|---------------------|------------------------------------------------------------------------------|
| `iconSpaceReserved` | `boolean`: set`true`if the space for the icon view should be reserved <br /> |

### setIntent

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setIntent (Intent intent)
```

Sets an[Intent](https://developer.android.com/reference/android/content/Intent.html)to be used for[startActivity(Intent)](https://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent))when this Preference is clicked.

<br />

|                               Parameters                               ||
|----------|--------------------------------------------------------------|
| `intent` | `Intent`: The intent associated with this Preference. <br /> |

### setKey

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setKey (String key)
```

Sets the key for this Preference, which is used as a key to the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)or[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore). This should be unique for the package.

<br />

|                     Parameters                      ||
|-------|----------------------------------------------|
| `key` | `String`: The key for the preference. <br /> |

### setLayoutResource

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setLayoutResource (int layoutResId)
```

Sets the layout resource that is inflated as the[View](https://developer.android.com/reference/android/view/View.html)to be shown for this Preference. In most cases, the default layout is sufficient for custom Preference objects and only the widget layout needs to be changed.

This layout should contain a[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)with ID[widget_frame](https://developer.android.com/reference/android/R.id#widget_frame)to be the parent of the specific widget for this Preference. It should similarly contain[title](https://developer.android.com/reference/android/R.id#title)and[summary](https://developer.android.com/reference/android/R.id#summary).

It is an error to change the layout after adding the preference to a[PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)

<br />

|                                                                         Parameters                                                                          ||
|---------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `layoutResId` | `int`: The layout resource ID to be inflated and returned as a[View](https://developer.android.com/reference/android/view/View.html). <br /> |

**See also:**

- [setWidgetLayoutResource(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#setWidgetLayoutResource(int))  

### setOnPreferenceChangeListener

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setOnPreferenceChangeListener (Preference.OnPreferenceChangeListener onPreferenceChangeListener)
```

Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).

<br />

|                                                Parameters                                                 ||
|------------------------------|-----------------------------------------------------------------------------|
| `onPreferenceChangeListener` | `Preference.OnPreferenceChangeListener`: The callback to be invoked. <br /> |

### setOnPreferenceClickListener

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setOnPreferenceClickListener (Preference.OnPreferenceClickListener onPreferenceClickListener)
```

Sets the callback to be invoked when this Preference is clicked.

<br />

|                                               Parameters                                                ||
|-----------------------------|----------------------------------------------------------------------------|
| `onPreferenceClickListener` | `Preference.OnPreferenceClickListener`: The callback to be invoked. <br /> |

### setOrder

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setOrder (int order)
```

Sets the order of this Preference with respect to other Preference objects on the same level. If this is not specified, the default behavior is to sort alphabetically. The[setOrderingAsAdded(boolean)](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup#setOrderingAsAdded(boolean))can be used to order Preference objects based on the order they appear in the XML.

<br />

|                                                                                                                          Parameters                                                                                                                           ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `order` | `int`: The order for this Preference. A lower value will be shown first. Use[DEFAULT_ORDER](https://developer.android.com/reference/android/support/v7/preference/Preference#DEFAULT_ORDER)to sort alphabetically or allow ordering from XML. <br /> |

**See also:**

- [setOrderingAsAdded(boolean)](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup#setOrderingAsAdded(boolean))
- [DEFAULT_ORDER](https://developer.android.com/reference/android/support/v7/preference/Preference#DEFAULT_ORDER)  

### setPersistent

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setPersistent (boolean persistent)
```

Sets whether this Preference is persistent. When persistent, it stores its value(s) into the persistent[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)storage by default or into[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)if assigned.

<br />

|                                         Parameters                                         ||
|--------------|------------------------------------------------------------------------------|
| `persistent` | `boolean`: set`true`if it should store its value(s) into the storage. <br /> |

### setPreferenceDataStore

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setPreferenceDataStore (PreferenceDataStore dataStore)
```

Sets a[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)to be used by this Preference instead of using[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html).

The data store will remain assigned even if the Preference is moved around the preference hierarchy. It will also override a data store propagated from the[PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)that owns this Preference.

<br />

|                                                                                         Parameters                                                                                          ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dataStore` | `PreferenceDataStore`: the[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)to be used by this Preference <br /> |

**See also:**

- [setPreferenceDataStore(PreferenceDataStore)](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager#setPreferenceDataStore(android.support.v7.preference.PreferenceDataStore))  

### setSelectable

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setSelectable (boolean selectable)
```

Sets whether this Preference is selectable.

<br />

|                           Parameters                            ||
|--------------|---------------------------------------------------|
| `selectable` | `boolean`: Set true to make it selectable. <br /> |

### setShouldDisableView

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setShouldDisableView (boolean shouldDisableView)
```

Sets whether this Preference should disable its view when it gets disabled.

For example, set this and[setEnabled(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#setEnabled(boolean))to false for preferences that are only displaying information and 1) should not be clickable 2) should not have the view set to the disabled state.

<br />

|                                                         Parameters                                                          ||
|---------------------|--------------------------------------------------------------------------------------------------------|
| `shouldDisableView` | `boolean`: Set true if this preference should disable its view when the preference is disabled. <br /> |

### setSingleLineTitle

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setSingleLineTitle (boolean singleLineTitle)
```

Sets whether to constrain the title of this Preference to a single line instead of letting it wrap onto multiple lines.

<br />

**Related XML Attributes:**

- [Preference_android_singleLineTitle](https://developer.android.com/reference/android/support/v7/preference/Preference#attr_Preference_android_singleLineTitle)

|                                          Parameters                                          ||
|-------------------|---------------------------------------------------------------------------|
| `singleLineTitle` | `boolean`: set`true`if the title should be constrained to one line <br /> |

### setSummary

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setSummary (CharSequence summary)
```

Sets the summary for this Preference with a CharSequence.

<br />

|                            Parameters                             ||
|-----------|--------------------------------------------------------|
| `summary` | `CharSequence`: The summary for the preference. <br /> |

### setSummary

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setSummary (int summaryResId)
```

Sets the summary for this Preference with a resource ID.

<br />

|                        Parameters                        ||
|----------------|------------------------------------------|
| `summaryResId` | `int`: The summary as a resource. <br /> |

**See also:**

- [setSummary(CharSequence)](https://developer.android.com/reference/android/support/v7/preference/Preference#setSummary(java.lang.CharSequence))  

### setTitle

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setTitle (CharSequence title)
```

Sets the title for this Preference with a CharSequence. This title will be placed into the ID[title](https://developer.android.com/reference/android/R.id#title)within the View bound by[onBindViewHolder(PreferenceViewHolder)](https://developer.android.com/reference/android/support/v7/preference/Preference#onBindViewHolder(android.support.v7.preference.PreferenceViewHolder)).

<br />

|                           Parameters                           ||
|---------|-------------------------------------------------------|
| `title` | `CharSequence`: The title for this Preference. <br /> |

### setTitle

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setTitle (int titleResId)
```

Sets the title for this Preference with a resource ID.

<br />

|                       Parameters                        ||
|--------------|-------------------------------------------|
| `titleResId` | `int`: The title as a resource ID. <br /> |

**See also:**

- [setTitle(CharSequence)](https://developer.android.com/reference/android/support/v7/preference/Preference#setTitle(java.lang.CharSequence))  

### setViewId

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setViewId (int viewId)
```

Set the ID that will be assigned to the overall View representing this preference, once bound.

<br />

|       Parameters       ||
|----------|--------------|
| `viewId` | `int` <br /> |

**See also:**

- [setId(int)](https://developer.android.com/https://developer.android.com/reference/android/view/View#setId(int))  

### setVisible

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setVisible (boolean visible)
```

Sets whether this preference should be visible in the list. If false, it is excluded from the adapter, but can still be retrieved using[findPreference(CharSequence)](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat#findPreference(java.lang.CharSequence)).

<br />

|                                        Parameters                                         ||
|-----------|--------------------------------------------------------------------------------|
| `visible` | `boolean`: Set false if this preference should be hidden from the list. <br /> |

### setWidgetLayoutResource

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setWidgetLayoutResource (int widgetLayoutResId)
```

Sets the layout for the controllable widget portion of this Preference. This is inflated into the main layout. For example, a[CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)would specify a custom layout (consisting of just the CheckBox) here, instead of creating its own main layout.

It is an error to change the layout after adding the preference to a[PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)

<br />

|                                           Parameters                                           ||
|---------------------|---------------------------------------------------------------------------|
| `widgetLayoutResId` | `int`: The layout resource ID to be inflated into the main layout. <br /> |

**See also:**

- [setLayoutResource(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#setLayoutResource(int))  

### shouldDisableDependents

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean shouldDisableDependents ()
```

Checks whether this preference's dependents should currently be disabled.

<br />

|                                    Returns                                    ||
|-----------|--------------------------------------------------------------------|
| `boolean` | True if the dependents should be disabled, otherwise false. <br /> |

### toString

```
String toString ()
```

<br />

<br />

|     Returns      ||
|----------|--------|
| `String` | <br /> |

## Protected methods

### findPreferenceInHierarchy

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Preference findPreferenceInHierarchy (String key)
```

Finds a Preference in this hierarchy (the whole thing, even above/below your[PreferenceScreen](https://developer.android.com/reference/android/support/v7/preference/PreferenceScreen)screen break) with the given key.

This only functions after we have been attached to a hierarchy.

<br />

|                         Parameters                         ||
|-------|-----------------------------------------------------|
| `key` | `String`: The key of the Preference to find. <br /> |

|                                                                    Returns                                                                     ||
|------------------------------------------------------------------------------------------------|------------------------------------------------|
| [Preference](https://developer.android.com/reference/android/support/v7/preference/Preference) | The Preference that uses the given key. <br /> |

### getPersistedBoolean

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean getPersistedBoolean (boolean defaultReturnValue)
```

Attempts to get a persisted[Boolean](https://developer.android.com/reference/java/lang/Boolean)if this Preference is persistent.

<br />

|                                                                             Parameters                                                                              ||
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `defaultReturnValue` | `boolean`: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | the value from the storage or the default return value <br /> |

**See also:**

- [getPersistedString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String))
- [persistBoolean(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistBoolean(boolean))  

### getPersistedFloat

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
float getPersistedFloat (float defaultReturnValue)
```

Attempts to get a persisted[Float](https://developer.android.com/reference/java/lang/Float)if this Preference is persistent.

<br />

|                                                                            Parameters                                                                             ||
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `defaultReturnValue` | `float`: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. <br /> |

|                                Returns                                 ||
|---------|---------------------------------------------------------------|
| `float` | the value from the storage or the default return value <br /> |

**See also:**

- [getPersistedString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String))
- [persistFloat(float)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistFloat(float))  

### getPersistedInt

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getPersistedInt (int defaultReturnValue)
```

Attempts to get a persisted[Integer](https://developer.android.com/reference/java/lang/Integer)if this Preference is persistent.

<br />

|                                                                           Parameters                                                                            ||
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `defaultReturnValue` | `int`: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. <br /> |

|                               Returns                                ||
|-------|---------------------------------------------------------------|
| `int` | the value from the storage or the default return value <br /> |

**See also:**

- [getPersistedString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String))
- [persistInt(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistInt(int))  

### getPersistedLong

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
long getPersistedLong (long defaultReturnValue)
```

Attempts to get a persisted[Long](https://developer.android.com/reference/java/lang/Long)if this Preference is persistent.

<br />

|                                                                            Parameters                                                                            ||
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `defaultReturnValue` | `long`: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. <br /> |

|                                Returns                                ||
|--------|---------------------------------------------------------------|
| `long` | the value from the storage or the default return value <br /> |

**See also:**

- [getPersistedString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String))
- [persistLong(long)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistLong(long))  

### getPersistedString

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getPersistedString (String defaultReturnValue)
```

Attempts to get a persisted set of Strings if this Preference is persistent.

<br />

|                                                                            Parameters                                                                             ||
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `defaultReturnValue` | `String`: The default value to return if either the Preference is not persistent or the Preference is not in the shared preferences. <br /> |

|                                 Returns                                 ||
|----------|---------------------------------------------------------------|
| `String` | the value from the storage or the default return value <br /> |

**See also:**

- [persistString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistString(java.lang.String))  

### notifyChanged

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void notifyChanged ()
```

Should be called when the data of this[Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)has changed.

<br />

### notifyHierarchyChanged

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void notifyHierarchyChanged ()
```

Should be called when a Preference has been added/removed from this group, or the ordering should be re-evaluated.

<br />

### onAttachedToHierarchy

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onAttachedToHierarchy (PreferenceManager preferenceManager)
```

Called when this Preference has been attached to a Preference hierarchy. Make sure to call the super implementation.

<br />

|                                        Parameters                                        ||
|---------------------|---------------------------------------------------------------------|
| `preferenceManager` | `PreferenceManager`: The PreferenceManager of the hierarchy. <br /> |

### onClick

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onClick ()
```

Processes a click on the preference. This includes saving the value to the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html). However, the overridden method should call[callChangeListener(Object)](https://developer.android.com/reference/android/support/v7/preference/Preference#callChangeListener(java.lang.Object))to make sure the client wants to update the preference's state with the new value.

<br />

### onGetDefaultValue

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Object onGetDefaultValue (TypedArray a, 
                int index)
```

Called when a Preference is being inflated and the default value attribute needs to be read. Since different Preference types have different value types, the subclass should get and return the default value which will be its value type.

For example, if the value type is String, the body of the method would proxy to[getString(int)](https://developer.android.com/reference/android/content/res/TypedArray.html#getString(int)).

<br />

|                            Parameters                            ||
|---------|---------------------------------------------------------|
| `a`     | `TypedArray`: The set of attributes. <br />             |
| `index` | `int`: The index of the default value attribute. <br /> |

|                           Returns                           ||
|----------|---------------------------------------------------|
| `Object` | The default value of this preference type. <br /> |

### onPrepareForRemoval

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onPrepareForRemoval ()
```

Called when this Preference is being removed from the hierarchy. You should remove any references to this Preference that you know about. Make sure to call through to the superclass implementation.

<br />

### onRestoreInstanceState

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onRestoreInstanceState (Parcelable state)
```

Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by[onSaveInstanceState()](https://developer.android.com/reference/android/support/v7/preference/Preference#onSaveInstanceState()). This function will never be called with a null state.

<br />

|                                                                                                     Parameters                                                                                                     ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `state` | `Parcelable`: The saved state that had previously been returned by[onSaveInstanceState()](https://developer.android.com/reference/android/support/v7/preference/Preference#onSaveInstanceState()). <br /> |

**See also:**

- [onSaveInstanceState()](https://developer.android.com/reference/android/support/v7/preference/Preference#onSaveInstanceState())
- [restoreHierarchyState(Bundle)](https://developer.android.com/reference/android/support/v7/preference/Preference#restoreHierarchyState(android.os.Bundle))  

### onSaveInstanceState

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Parcelable onSaveInstanceState ()
```

Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can be reconstructed later.

<br />

|                                                                                                                             Returns                                                                                                                             ||
|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Parcelable](https://developer.android.com/reference/android/os/Parcelable.html) | A Parcelable object containing the current dynamic state of this Preference, or null if there is nothing interesting to save. The default implementation returns null. <br /> |

**See also:**

- [onRestoreInstanceState(Parcelable)](https://developer.android.com/reference/android/support/v7/preference/Preference#onRestoreInstanceState(android.os.Parcelable))
- [saveHierarchyState(Bundle)](https://developer.android.com/reference/android/support/v7/preference/Preference#saveHierarchyState(android.os.Bundle))  

### onSetInitialValue

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onSetInitialValue (boolean restorePersistedValue, 
                Object defaultValue)
```

Implement this to set the initial value of the Preference.

If<var translate="no">restorePersistedValue</var>is true, you should restore the Preference value from the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html). If<var translate="no">restorePersistedValue</var>is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if[shouldPersist()](https://developer.android.com/reference/android/support/v7/preference/Preference#shouldPersist())is true).

In case of using[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore), the<var translate="no">restorePersistedValue</var>is always`true`but the default value (if provided) is set.

This may not always be called. One example is if it should not persist but there is no default value given.

<br />

|                                                                        Parameters                                                                         ||
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| `restorePersistedValue` | `boolean`: True to restore the persisted value; false to use the given<var translate="no">defaultValue</var>. <br />             |
| `defaultValue`          | `Object`: The default value for this Preference. Only use this if<var translate="no">restorePersistedValue</var>is false. <br /> |

### persistBoolean

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean persistBoolean (boolean value)
```

Attempts to persist a[Boolean](https://developer.android.com/reference/java/lang/Boolean)if this Preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

<br />

|                    Parameters                    ||
|---------|-----------------------------------------|
| `value` | `boolean`: The value to persist. <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | `true`if the Preference is persistent,`false`otherwise <br /> |

**See also:**

- [persistString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistString(java.lang.String))
- [getPersistedBoolean(boolean)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedBoolean(boolean))  

### persistFloat

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean persistFloat (float value)
```

Attempts to persist a[Float](https://developer.android.com/reference/java/lang/Float)if this Preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

<br />

|                   Parameters                   ||
|---------|---------------------------------------|
| `value` | `float`: The value to persist. <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | `true`if the Preference is persistent,`false`otherwise <br /> |

**See also:**

- [persistString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistString(java.lang.String))
- [getPersistedFloat(float)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedFloat(float))  

### persistInt

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean persistInt (int value)
```

Attempts to persist an[Integer](https://developer.android.com/reference/java/lang/Integer)if this Preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

<br />

|                  Parameters                  ||
|---------|-------------------------------------|
| `value` | `int`: The value to persist. <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | `true`if the Preference is persistent,`false`otherwise <br /> |

**See also:**

- [persistString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistString(java.lang.String))
- [getPersistedInt(int)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedInt(int))  

### persistLong

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean persistLong (long value)
```

Attempts to persist a[Long](https://developer.android.com/reference/java/lang/Long)if this Preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

<br />

|                  Parameters                   ||
|---------|--------------------------------------|
| `value` | `long`: The value to persist. <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | `true`if the Preference is persistent,`false`otherwise <br /> |

**See also:**

- [persistString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#persistString(java.lang.String))
- [getPersistedLong(long)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedLong(long))  

### persistString

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean persistString (String value)
```

Attempts to persist a[String](https://developer.android.com/reference/java/lang/String)if this Preference is persistent.

The returned value doesn't reflect whether the given value was persisted, since we may not necessarily commit if there will be a batch commit later.

<br />

|                   Parameters                    ||
|---------|----------------------------------------|
| `value` | `String`: The value to persist. <br /> |

|                                 Returns                                  ||
|-----------|---------------------------------------------------------------|
| `boolean` | `true`if the Preference is persistent,`false`otherwise <br /> |

**See also:**

- [getPersistedString(String)](https://developer.android.com/reference/android/support/v7/preference/Preference#getPersistedString(java.lang.String))  

### shouldPersist

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean shouldPersist ()
```

Checks whether, at the given time this method is called, this Preference should store/restore its value(s) into the[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html)or into[PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)if assigned. This, at minimum, checks whether this Preference is persistent and it currently has a key. Before you save/restore from the storage, check this first.

<br />

|                        Returns                         ||
|-----------|---------------------------------------------|
| `boolean` | `true`if it should persist the value <br /> |

-

  ## Interfaces

  - [DialogPreference.TargetFragment](https://developer.android.com/reference/android/support/v7/preference/DialogPreference.TargetFragment)
  - [Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceChangeListener)
  - [Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/support/v7/preference/Preference.OnPreferenceClickListener)
  - [PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback)
  - [PreferenceFragmentCompat.OnPreferenceStartFragmentCallback](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat.OnPreferenceStartFragmentCallback)
  - [PreferenceFragmentCompat.OnPreferenceStartScreenCallback](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat.OnPreferenceStartScreenCallback)
  - [PreferenceGroup.PreferencePositionCallback](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup.PreferencePositionCallback)
  - [PreferenceManager.OnDisplayPreferenceDialogListener](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager.OnDisplayPreferenceDialogListener)
  - [PreferenceManager.OnNavigateToScreenListener](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager.OnNavigateToScreenListener)
  - [PreferenceManager.OnPreferenceTreeClickListener](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager.OnPreferenceTreeClickListener)
-

  ## Classes

  - [CheckBoxPreference](https://developer.android.com/reference/android/support/v7/preference/CheckBoxPreference)
  - [DialogPreference](https://developer.android.com/reference/android/support/v7/preference/DialogPreference)
  - [DropDownPreference](https://developer.android.com/reference/android/support/v7/preference/DropDownPreference)
  - [EditTextPreference](https://developer.android.com/reference/android/support/v7/preference/EditTextPreference)
  - [EditTextPreferenceDialogFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/EditTextPreferenceDialogFragmentCompat)
  - [ListPreference](https://developer.android.com/reference/android/support/v7/preference/ListPreference)
  - [ListPreferenceDialogFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/ListPreferenceDialogFragmentCompat)
  - [MultiSelectListPreferenceDialogFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/MultiSelectListPreferenceDialogFragmentCompat)
  - [Preference](https://developer.android.com/reference/android/support/v7/preference/Preference)
  - [Preference.BaseSavedState](https://developer.android.com/reference/android/support/v7/preference/Preference.BaseSavedState)
  - [PreferenceCategory](https://developer.android.com/reference/android/support/v7/preference/PreferenceCategory)
  - [PreferenceDataStore](https://developer.android.com/reference/android/support/v7/preference/PreferenceDataStore)
  - [PreferenceDialogFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/PreferenceDialogFragmentCompat)
  - [PreferenceFragmentCompat](https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat)
  - [PreferenceGroup](https://developer.android.com/reference/android/support/v7/preference/PreferenceGroup)
  - [PreferenceManager](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager)
  - [PreferenceManager.PreferenceComparisonCallback](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager.PreferenceComparisonCallback)
  - [PreferenceManager.SimplePreferenceComparisonCallback](https://developer.android.com/reference/android/support/v7/preference/PreferenceManager.SimplePreferenceComparisonCallback)
  - [PreferenceScreen](https://developer.android.com/reference/android/support/v7/preference/PreferenceScreen)
  - [PreferenceViewHolder](https://developer.android.com/reference/android/support/v7/preference/PreferenceViewHolder)
  - [R](https://developer.android.com/reference/android/support/v7/preference/R)
  - [R.anim](https://developer.android.com/reference/android/support/v7/preference/R.anim)
  - [R.attr](https://developer.android.com/reference/android/support/v7/preference/R.attr)
  - [R.bool](https://developer.android.com/reference/android/support/v7/preference/R.bool)
  - [R.color](https://developer.android.com/reference/android/support/v7/preference/R.color)
  - [R.dimen](https://developer.android.com/reference/android/support/v7/preference/R.dimen)
  - [R.drawable](https://developer.android.com/reference/android/support/v7/preference/R.drawable)
  - [R.id](https://developer.android.com/reference/android/support/v7/preference/R.id)
  - [R.integer](https://developer.android.com/reference/android/support/v7/preference/R.integer)
  - [R.layout](https://developer.android.com/reference/android/support/v7/preference/R.layout)
  - [R.string](https://developer.android.com/reference/android/support/v7/preference/R.string)
  - [R.style](https://developer.android.com/reference/android/support/v7/preference/R.style)
  - [R.styleable](https://developer.android.com/reference/android/support/v7/preference/R.styleable)
  - [SeekBarPreference](https://developer.android.com/reference/android/support/v7/preference/SeekBarPreference)
  - [SwitchPreferenceCompat](https://developer.android.com/reference/android/support/v7/preference/SwitchPreferenceCompat)
  - [TwoStatePreference](https://developer.android.com/reference/android/support/v7/preference/TwoStatePreference)