Google is committed to advancing racial equity for Black communities. See how.
Added in API level 14
Deprecated in API level 29

TwoStatePreference

abstract class TwoStatePreference : Preference
kotlin.Any
   ↳ android.preference.Preference
   ↳ android.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.

Summary

Inherited XML attributes
Inherited constants
Public constructors
<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!)

Public methods
open Boolean

Returns whether dependents are disabled when this preference is on (true) or when this preference is off (false).

open CharSequence!

Returns the summary to be shown when unchecked.

open CharSequence!

Returns the summary to be shown when checked.

open Boolean

Returns the checked state.

open Unit
setChecked(checked: Boolean)

Sets the checked state and saves it to the SharedPreferences.

open Unit
setDisableDependentsState(disableDependentsState: Boolean)

Sets whether dependents are disabled when this preference is on (true) or when this preference is off (false).

open Unit

Sets the summary to be shown when unchecked.

open Unit
setSummaryOff(summaryResId: Int)

open Unit

Sets the summary to be shown when checked.

open Unit
setSummaryOn(summaryResId: Int)

open Boolean

Protected methods
open Unit

open Any!

open Unit

open Parcelable!

open Unit
onSetInitialValue(restoreValue: Boolean, defaultValue: Any!)

Inherited functions

Public constructors

<init>

Added in API level 21
TwoStatePreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

<init>

Added in API level 14
TwoStatePreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

<init>

Added in API level 14
TwoStatePreference(
    context: Context!,
    attrs: AttributeSet!)

<init>

Added in API level 14
TwoStatePreference(context: Context!)

Public methods

getDisableDependentsState

Added in API level 14
Deprecated in API level 29
open fun getDisableDependentsState(): Boolean

Deprecated.

Returns whether dependents are disabled when this preference is on (true) or when this preference is off (false).

Return
Boolean Whether dependents are disabled when this preference is on (true) or when this preference is off (false).

getSummaryOff

Added in API level 14
Deprecated in API level 29
open fun getSummaryOff(): CharSequence!

Deprecated.

Returns the summary to be shown when unchecked.

Return
CharSequence! The summary.

getSummaryOn

Added in API level 14
Deprecated in API level 29
open fun getSummaryOn(): CharSequence!

Deprecated.

Returns the summary to be shown when checked.

Return
CharSequence! The summary.

isChecked

Added in API level 14
Deprecated in API level 29
open fun isChecked(): Boolean

Deprecated.

Returns the checked state.

Return
Boolean The checked state.

setChecked

Added in API level 14
Deprecated in API level 29
open fun setChecked(checked: Boolean): Unit

Deprecated.

Sets the checked state and saves it to the SharedPreferences.

Parameters
checked Boolean: The checked state.

setDisableDependentsState

Added in API level 14
Deprecated in API level 29
open fun setDisableDependentsState(disableDependentsState: Boolean): Unit

Deprecated.

Sets whether dependents are disabled when this preference is on (true) or when this preference is off (false).

Parameters
disableDependentsState Boolean: The preference state that should disable dependents.

setSummaryOff

Added in API level 14
Deprecated in API level 29
open fun setSummaryOff(summary: CharSequence!): Unit

Deprecated.

Sets the summary to be shown when unchecked.

Parameters
summary CharSequence!: The summary to be shown when unchecked.

setSummaryOff

Added in API level 14
Deprecated in API level 29
open fun setSummaryOff(summaryResId: Int): Unit

Deprecated.

Parameters
summaryResId Int: The summary as a resource.

setSummaryOn

Added in API level 14
Deprecated in API level 29
open fun setSummaryOn(summary: CharSequence!): Unit

Deprecated.

Sets the summary to be shown when checked.

Parameters
summary CharSequence!: The summary to be shown when checked.

setSummaryOn

Added in API level 14
Deprecated in API level 29
open fun setSummaryOn(summaryResId: Int): Unit

Deprecated.

Parameters
summaryResId Int: The summary as a resource.

shouldDisableDependents

Added in API level 14
Deprecated in API level 29
open fun shouldDisableDependents(): Boolean

Deprecated.

Return
Boolean True if the dependents should be disabled, otherwise false.

Protected methods

onClick

Added in API level 14
Deprecated in API level 29
protected open fun onClick(): Unit

Deprecated.

onGetDefaultValue

Added in API level 14
Deprecated in API level 29
protected open fun onGetDefaultValue(
    a: TypedArray!,
    index: Int
): Any!

Deprecated.

Parameters
a TypedArray!: The set of attributes.
index Int: The index of the default value attribute.
Return
Any! The default value of this preference type.

onRestoreInstanceState

Added in API level 14
Deprecated in API level 29
protected open fun onRestoreInstanceState(state: Parcelable!): Unit

Deprecated.

Parameters
state Parcelable!: The saved state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 14
Deprecated in API level 29
protected open fun onSaveInstanceState(): Parcelable!

Deprecated.

Return
Parcelable! 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.

onSetInitialValue

Added in API level 14
Deprecated in API level 29
protected open fun onSetInitialValue(
    restoreValue: Boolean,
    defaultValue: Any!
): Unit

Deprecated.

Parameters
restorePersistedValue True to restore the persisted value; false to use the given defaultValue.
defaultValue Any!: The default value for this Preference. Only use this if restorePersistedValue is false.