# androidx.preference

*** ** * ** ***

The Preference library allows you to build interactive settings screens, without needing to handle interacting with device storage or managing the user interface.

## Interfaces

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference.TargetFragment` | Interface for `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat`s to implement to allow `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference`s to find the preference that launched the dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference.OnBindEditTextListener` | Interface definition for a callback to be invoked when the corresponding dialog view for this preference is bound. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener` | Interface definition for a callback to be invoked when the value of this `https://developer.android.com/reference/kotlin/androidx/preference/Preference` has been changed by the user and is about to be set and/or persisted. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceClickListener` | Interface definition for a callback to be invoked when a `https://developer.android.com/reference/kotlin/androidx/preference/Preference` is clicked. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` | Interface definition for a callback to be invoked when the summary of this `https://developer.android.com/reference/kotlin/androidx/preference/Preference` is requested (typically when this preference is added to the hierarchy or its value is updated). |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragment.OnPreferenceDisplayDialogCallback` | **This interface is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragment.OnPreferenceStartFragmentCallback` | **This interface is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragment.OnPreferenceStartScreenCallback` | **This interface is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback` | Interface that the fragment's containing activity should implement to be able to process preference items that wish to display a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat.OnPreferenceStartFragmentCallback` | Interface that the fragment's containing activity should implement to be able to process preference items that wish to switch to a specified fragment. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat.OnPreferenceStartScreenCallback` | Interface that the fragment's containing activity should implement to be able to process preference items that wish to switch to a new screen of preferences. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.PreferencePositionCallback` | Interface for PreferenceGroup adapters to implement so that `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat#scrollToPreference(java.lang.String)` and `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat#scrollToPreference(androidx.preference.Preference)` can determine the correct scroll position to request. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.OnDisplayPreferenceDialogListener` | Interface definition for a class that will be called when a `https://developer.android.com/reference/kotlin/androidx/preference/Preference` requests to display a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.OnNavigateToScreenListener` | Interface definition for a class that will be called when a `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen` requests navigation. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.OnPreferenceTreeClickListener` | Interface definition for a callback to be invoked when a `https://developer.android.com/reference/kotlin/androidx/preference/Preference` in the hierarchy rooted at this `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen` is clicked. |

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/preference/CheckBoxPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that provides checkbox widget functionality. |
| `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference` | A base class for `https://developer.android.com/reference/kotlin/androidx/preference/Preference`s that are dialog-based. |
| `https://developer.android.com/reference/kotlin/androidx/preference/DropDownPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/ListPreference` that presents the options in a drop down menu rather than a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference` that shows a `https://developer.android.com/reference/android/widget/EditText.html` in the dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference.SimpleSummaryProvider` | A simple `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` implementation for an `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreference`. |
| `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreferenceDialogFragment` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreferenceDialogFragmentCompat` instead <br /> |
| `https://developer.android.com/reference/kotlin/androidx/preference/EditTextPreferenceDialogFragmentCompat` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/ListPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that displays a list of entries as a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/ListPreference.SimpleSummaryProvider` | A simple `https://developer.android.com/reference/kotlin/androidx/preference/Preference.SummaryProvider` implementation for a `https://developer.android.com/reference/kotlin/androidx/preference/ListPreference`. |
| `https://developer.android.com/reference/kotlin/androidx/preference/ListPreferenceDialogFragment` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/preference/ListPreferenceDialogFragmentCompat` instead <br /> |
| `https://developer.android.com/reference/kotlin/androidx/preference/ListPreferenceDialogFragmentCompat` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/MultiSelectListPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that displays a list of entries as a dialog. |
| `https://developer.android.com/reference/kotlin/androidx/preference/MultiSelectListPreferenceDialogFragment` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/preference/MultiSelectListPreferenceDialogFragmentCompat` instead <br /> |
| `https://developer.android.com/reference/kotlin/androidx/preference/MultiSelectListPreferenceDialogFragmentCompat` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference` | The basic building block that represents an individual setting displayed to a user in the preference hierarchy. |
| `https://developer.android.com/reference/kotlin/androidx/preference/Preference.BaseSavedState` | A base class for managing the instance state of a `https://developer.android.com/reference/kotlin/androidx/preference/Preference`. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceCategory` | A container that is used to group similar `https://developer.android.com/reference/kotlin/androidx/preference/Preference`s. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDataStore` | A data store interface to be implemented and provided to the `https://developer.android.com/reference/kotlin/androidx/preference/Preference` framework. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDialogFragment` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDialogFragmentCompat` instead <br /> |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceDialogFragmentCompat` | Abstract base class which presents a dialog associated with a `https://developer.android.com/reference/kotlin/androidx/preference/DialogPreference`. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragment` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat` instead <br /> |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat` | A PreferenceFragmentCompat is the entry point to using the Preference library. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup` | A container for multiple `https://developer.android.com/reference/kotlin/androidx/preference/Preference`s. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceHeaderFragmentCompat` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceHeaderFragmentCompat` implements a two-pane fragment for preferences. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager` | Used to help create `https://developer.android.com/reference/kotlin/androidx/preference/Preference` hierarchies from activities or XML. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.PreferenceComparisonCallback` | Callback class to be used by the `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter` associated with the `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen`, used to determine when two `https://developer.android.com/reference/kotlin/androidx/preference/Preference` objects are semantically and visually the same. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.SimplePreferenceComparisonCallback` | A basic implementation of `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceManager.PreferenceComparisonCallback` suitable for use with the default `https://developer.android.com/reference/kotlin/androidx/preference/Preference` classes. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceScreen` | A top-level container that represents a settings screen. |
| `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder` | A `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder` class which caches views associated with the default `https://developer.android.com/reference/kotlin/androidx/preference/Preference` layouts. |
| `https://developer.android.com/reference/kotlin/androidx/preference/R` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/R.attr` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/R.style` |   |
| `https://developer.android.com/reference/kotlin/androidx/preference/SeekBarPreference` | Preference based on android.preference.SeekBarPreference but uses support preference as a base . |
| `https://developer.android.com/reference/kotlin/androidx/preference/SwitchPreference` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that provides a two-state toggleable option. |
| `https://developer.android.com/reference/kotlin/androidx/preference/SwitchPreferenceCompat` | A `https://developer.android.com/reference/kotlin/androidx/preference/Preference` that provides a two-state toggleable option. |
| `https://developer.android.com/reference/kotlin/androidx/preference/TwoStatePreference` | Common base class for preferences that have two selectable states, save a boolean value, and may have dependent preferences that are enabled/disabled based on the current state. |

## Extension functions summary

|---|---|
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).contains(androidx.preference.Preference)(preference: https://developer.android.com/reference/kotlin/androidx/preference/Preference)` Returns `true` if `preference` is found in this preference group. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).forEach(kotlin.Function1)(action: (preference: https://developer.android.com/reference/kotlin/androidx/preference/Preference) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Performs the given action on each preference in this preference group. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).forEachIndexed(kotlin.Function2)( action: (index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, preference: https://developer.android.com/reference/kotlin/androidx/preference/Preference) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Performs the given action on each preference in this preference group, providing its sequential index. |
| `operator https://developer.android.com/reference/kotlin/androidx/preference/Preference` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).get(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the preference at `index`. |
| `inline operator T?` | `<T : https://developer.android.com/reference/kotlin/androidx/preference/Preference> https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).get(kotlin.CharSequence)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)` Returns the preference with `key`, or `null` if no preference with `key` is found. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).isEmpty()()` Returns true if this preference group contains no preferences. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).isNotEmpty()()` Returns true if this preference group contains one or more preferences. |
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterator/index.html<https://developer.android.com/reference/kotlin/androidx/preference/Preference>` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).iterator()()` Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterator/index.html` over the preferences in this preference group. |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).minusAssign(androidx.preference.Preference)(preference: https://developer.android.com/reference/kotlin/androidx/preference/Preference)` Removes `preference` from this preference group. |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).plusAssign(androidx.preference.Preference)(preference: https://developer.android.com/reference/kotlin/androidx/preference/Preference)` Adds `preference` to this preference group. |

## Extension properties summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<https://developer.android.com/reference/kotlin/androidx/preference/Preference>` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).children()` Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html` over the preferences in this preference group. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.https://developer.android.com/reference/kotlin/androidx/preference/package-summary#(androidx.preference.PreferenceGroup).size()` Returns the number of preferences in this preference group. |

## Extension functions

### PreferenceGroup.contains

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:contains) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
operator fun PreferenceGroup.contains(preference: Preference): Boolean
```

Returns `true` if `preference` is found in this preference group.

### PreferenceGroup.forEach

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:forEach) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
inline fun PreferenceGroup.forEach(action: (preference: Preference) -> Unit): Unit
```

Performs the given action on each preference in this preference group.

### PreferenceGroup.forEachIndexed

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:forEachIndexed) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
inline fun PreferenceGroup.forEachIndexed(
    action: (index: Int, preference: Preference) -> Unit
): Unit
```

Performs the given action on each preference in this preference group, providing its sequential index.

### PreferenceGroup.get

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:get) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
operator fun PreferenceGroup.get(index: Int): Preference
```

Returns the preference at `index`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if index is less than 0 or greater than or equal to the count. |

### PreferenceGroup.get

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:get) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/preference#1.1.0)

```
inline operator fun <T : Preference> PreferenceGroup.get(key: CharSequence): T?
```

Returns the preference with `key`, or `null` if no preference with `key` is found.

### PreferenceGroup.isEmpty

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:isEmpty) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
inline fun PreferenceGroup.isEmpty(): Boolean
```

Returns true if this preference group contains no preferences.

### PreferenceGroup.isNotEmpty

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:isNotEmpty) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
inline fun PreferenceGroup.isNotEmpty(): Boolean
```

Returns true if this preference group contains one or more preferences.

### PreferenceGroup.iterator

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:iterator) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
operator fun PreferenceGroup.iterator(): Iterator<Preference>
```

Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterator/index.html` over the preferences in this preference group.

### PreferenceGroup.minusAssign

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:minusAssign) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
inline operator fun PreferenceGroup.minusAssign(preference: Preference): Unit
```

Removes `preference` from this preference group.

### PreferenceGroup.plusAssign

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+function:plusAssign) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
inline operator fun PreferenceGroup.plusAssign(preference: Preference): Unit
```

Adds `preference` to this preference group.

## Extension properties

### PreferenceGroup.children

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+symbol:children) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
val PreferenceGroup.children: Sequence<Preference>
```

Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html` over the preferences in this preference group.

### PreferenceGroup.size

Artifact: [androidx.preference:preference-ktx](https://developer.android.com/jetpack/androidx/releases/preference) [View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.kt+symbol:size) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/preference#1.0.0)

```
val PreferenceGroup.size: Int
```

Returns the number of preferences in this preference group.