O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

Preference

open class Preference : Comparable<Preference!>
kotlin.Any
   ↳ androidx.preference.Preference

The basic building block that represents an individual setting displayed to a user in the preference hierarchy. This class provides the data that will be displayed to the user and has a reference to the SharedPreferences or PreferenceDataStore instance that persists the preference's values.

When specifying a preference hierarchy in XML, each element can point to a subclass of Preference, similar to the view hierarchy and layouts.

This class contains a key that that represents the key that is used to persist the value to the device. It is up to the subclass to decide how to store the value.

Summary

Nested classes
open

A base class for managing the instance state of a Preference.

abstract

Interface definition for a callback to be invoked when the value of this Preference has been changed by the user and is about to be set and/or persisted.

abstract

Interface definition for a callback to be invoked when a Preference is clicked.

abstract

Interface definition for a callback to be invoked when the summary of this Preference is requested (typically when this preference is added to the hierarchy or its value is updated).

Constants
static Int

Specify for setOrder(int) if a specific order is not required.

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

Perform inflation from XML and apply a class-specific base style.

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

Perform inflation from XML and apply a class-specific base style.

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

Constructor that is called when inflating a preference from XML.

<init>(context: Context!)

Constructor to create a preference.

Public methods
open Boolean
callChangeListener(newValue: Any!)

Call this method after the user changes the preference, but before the internal state is set.

open Int
compareTo(@NonNull other: Preference)

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

open Context!

Returns the Context of this preference.

open String!

Returns the key of the dependency on this preference.

open Bundle!

Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one.

open String!

Return the fragment class name associated with this preference.

open Drawable!

Returns the icon of this preference.

open Intent!

Return the Intent associated with this preference.

open String!

Gets the key for this preference, which is also the key used for storing values into SharedPreferences or PreferenceDataStore.

Int

Gets the layout resource that will be shown as the View for this preference.

open Preference.OnPreferenceChangeListener!

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

open Preference.OnPreferenceClickListener!

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

open Int

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

open PreferenceGroup?

Returns the PreferenceGroup which is this preference assigned to or null if this preference is not assigned to any group or is a root preference.

open MutableSet<String!>!
getPersistedStringSet(defaultReturnValue: MutableSet<String!>!)

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

open PreferenceDataStore?

Returns PreferenceDataStore used by this preference.

open PreferenceManager!

Gets the PreferenceManager that manages this preference object's tree.

open SharedPreferences!

Returns the SharedPreferences where this preference can read its value(s).

open Boolean

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

open CharSequence!

Returns the summary of this preference.

Preference.SummaryProvider<Preference!>?

Returns the SummaryProvider used to configure the summary of this preference.

open CharSequence!

Returns the title of this preference.

Int

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

open Boolean

Checks whether this preference has a valid key.

open Boolean

Returns whether the summary of this preference can be copied to the clipboard by long pressing on the preference.

open Boolean

Checks whether this preference should be enabled in the list.

open Boolean

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

open Boolean

Checks whether this preference is persistent.

open Boolean

Checks whether this preference should be selectable in the list.

Boolean

Checks whether this preference is shown to the user in the hierarchy.

open Boolean

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

Boolean

Checks whether this preference should be visible to the user.

open Unit
notifyDependencyChange(disableDependents: Boolean)

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

open Unit

Called when the preference hierarchy has been attached to the list of preferences.

open Unit

Binds the created View to the data for this preference.

open Unit
onDependencyChanged(dependency: Preference!, disableDependent: Boolean)

Called when the dependency changes.

open Unit

Called when the preference hierarchy has been detached from the list of preferences.

open Unit

Initializes an android.view.accessibility.AccessibilityNodeInfo with information about the View for this preference.

open Unit
onParentChanged(parent: Preference!, disableChild: Boolean)

Called when the implicit parent dependency changes.

open Bundle!

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

open Boolean

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

open Unit

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

open Unit

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

open Unit

Sets whether the summary of this preference can be copied to the clipboard by long pressing on the preference.

open Unit
setDefaultValue(defaultValue: Any!)

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.

open Unit
setDependency(dependencyKey: String!)

Sets the key of a preference that this preference will depend on.

open Unit
setEnabled(enabled: Boolean)

Sets whether this preference is enabled.

open Unit
setFragment(fragment: String!)

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

open Unit
setIcon(icon: Drawable!)

Sets the icon for this preference with a Drawable.

open Unit
setIcon(iconResId: Int)

Sets the icon for this preference with a resource ID.

open Unit
setIconSpaceReserved(iconSpaceReserved: Boolean)

Sets whether to reserve the space of this preference icon view when no icon is provided.

open Unit
setIntent(intent: Intent!)

Sets an Intent to be used for Context#startActivity(Intent) when this preference is clicked.

open Unit
setKey(key: String!)

Sets the key for this preference, which is used as a key to the SharedPreferences or PreferenceDataStore.

open Unit
setLayoutResource(layoutResId: Int)

Sets the layout resource that is inflated as the View to be shown for this preference.

open Unit

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

open Unit

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

open Unit
setOrder(order: Int)

Sets the order of this preference with respect to other preference objects on the same level.

open Unit
setPersistent(persistent: Boolean)

Sets whether this preference is persistent.

open Unit

Sets a PreferenceDataStore to be used by this preference instead of using SharedPreferences.

open Unit
setSelectable(selectable: Boolean)

Sets whether this preference is selectable.

open Unit
setShouldDisableView(shouldDisableView: Boolean)

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

open Unit
setSingleLineTitle(singleLineTitle: Boolean)

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

open Unit

Sets the summary for this preference with a CharSequence.

open Unit
setSummary(summaryResId: Int)

Sets the summary for this preference with a resource ID.

Unit

Set a SummaryProvider that will be invoked whenever the summary of this preference is requested.

open Unit

Sets the title for this preference with a CharSequence.

open Unit
setTitle(titleResId: Int)

Sets the title for this preference with a resource ID.

open Unit
setViewId(viewId: Int)

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

Unit
setVisible(visible: Boolean)

Sets whether this preference should be visible to the user.

open Unit
setWidgetLayoutResource(widgetLayoutResId: Int)

Sets the layout for the controllable widget portion of this preference.

open Boolean

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

open String

Protected methods
open T?

Finds a preference in the entire hierarchy (above or below this preference) with the given key.

open Boolean
getPersistedBoolean(defaultReturnValue: Boolean)

Attempts to get a persisted Boolean if this preference is persistent.

open Float
getPersistedFloat(defaultReturnValue: Float)

Attempts to get a persisted Float if this preference is persistent.

open Int
getPersistedInt(defaultReturnValue: Int)

Attempts to get a persisted Integer if this preference is persistent.

open Long
getPersistedLong(defaultReturnValue: Long)

Attempts to get a persisted Long if this preference is persistent.

open String!
getPersistedString(defaultReturnValue: String!)

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

open Unit

Should be called when the data of this Preference has changed.

open Unit

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

open Unit

Called when this preference has been attached to a preference hierarchy.

open Unit

Processes a click on the preference.

open Any!

Called when a preference is being inflated and the default value attribute needs to be read.

open Unit

Called when this preference is being removed from the hierarchy.

open Unit

Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState.

open Parcelable!

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.

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

Implement this to set the initial value of the preference.

open Unit
onSetInitialValue(@Nullable defaultValue: Any?)

Implement this to set the initial value of the preference.

open Boolean

Attempts to persist a Boolean if this preference is persistent.

open Boolean

Attempts to persist a Float if this preference is persistent.

open Boolean
persistInt(value: Int)

Attempts to persist an Integer if this preference is persistent.

open Boolean
persistLong(value: Long)

Attempts to persist a Long if this preference is persistent.

open Boolean

Attempts to persist a String if this preference is persistent.

open Boolean

Checks whether, at the given time this method is called, this preference should store/restore its value(s) into the SharedPreferences or into PreferenceDataStore if assigned.

Constants

DEFAULT_ORDER

static val DEFAULT_ORDER: Int

Specify for setOrder(int) if a specific order is not required.

Value: Integer.MAX_VALUE

Public constructors

<init>

Preference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Perform inflation from XML and apply a class-specific base style. This constructor allows subclasses to use their own base style when they are inflating. For example, a CheckBoxPreference constructor calls this version of the super class constructor and supplies android.R.attr.checkBoxPreferenceStyle for defStyleAttr. This allows the theme's checkbox preference style to modify all of the base preference attributes as well as the CheckBoxPreference class's attributes.

Parameters
context Context!: The Context this is associated with, through which it can access the current theme, resources, SharedPreferences, etc.
attrs AttributeSet!: The attributes of the XML tag that is inflating the preference
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.
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