The default value for the preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage.
May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
May be an integer value, such as "100".
May be a boolean value, such as "true" or "false".
Whether the space for the preference icon view will be reserved. By default, preference icon view visibility will be set to GONE when there is no icon provided, so the default value of this attribute is false.
May be a boolean value, such as "true" or "false".
Whether to use single line for the preference title text. By default, preference title will be constrained to one line, so the default value of this attribute is true.
May be a boolean value, such as "true" or "false".
The layout for the controllable widget portion of a Preference. This is inflated into the layout for a Preference and should be used more frequently than the layout attribute. For example, a checkbox preference would specify a custom layout (consisting of just the CheckBox) here.
May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
Returns the android.content.Context of this Preference. Each Preference in a Preference hierarchy can be from different Context (for example, if multiple activities provide preferences into a single PreferenceActivity). This Context will be used to save the Preference values.
In some cases, writes to this will not be committed right away and hence not show up in the SharedPreferences, this is intended behavior to improve performance.
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.
In some cases, writes to the getEditor() will not be committed right away and hence not show up in the returned SharedPreferences, this is intended behavior to improve performance.
Checks whether this Preference is persistent. If it is, it stores its value(s) into the persistent SharedPreferences storage by default or into PreferenceDataStore if assigned.
Called when the Preference hierarchy has been attached to the PreferenceActivity. This can also be called when this Preference has been attached to a group that was already attached to the PreferenceActivity.
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 TypedArray#getString(int).
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. If you override this method you must call through to the superclass implementation.
Implement this to set the initial value of the Preference.
If restorePersistedValue is true, you should restore the Preference value from the android.content.SharedPreferences. If restorePersistedValue is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if shouldPersist() is true).
In case of using PreferenceDataStore, the restorePersistedValue 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.
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.
Sets the layout resource that is inflated as the View 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.
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 PreferenceGroup#setOrderingAsAdded(boolean) can be used to order Preference objects based on the order they appear in the XML.
Sets whether this Preference is persistent. When persistent, it stores its value(s) into the persistent SharedPreferences storage by default or into PreferenceDataStore if assigned.
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 that owns this Preference.
Sets whether this Preference has enabled to have its view recycled when used in the list view. By default the recycling is enabled.
The value can be changed only before this preference is added to the preference hierarchy.
If view recycling is not allowed then each time the list view populates this preference the getView(android.view.View,android.view.ViewGroup) method receives a null convert view and needs to recreate the view. Otherwise view gets recycled and only onBindView(android.view.View) gets called. If you override this method you must call through to the superclass implementation.
Sets whether this Preference should disable its view when it gets disabled.
For example, set this and 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.
Sets the layout for the controllable widget portion of this Preference. This is inflated into the main layout. For example, a CheckBoxPreference would specify a custom layout (consisting of just the CheckBox) here, instead of creating its own main layout.
Returns whether the Preference should commit its saved value(s) in getEditor(). This may return false in situations where batch committing is being done (by the manager) to improve performance.
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. 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.
May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
android:dialogLayout
android:dialogLayout
A layout to be used as the content View for the dialog. By default, this shouldn't be needed. If a custom DialogPreference is required, this should be set. For example, the EditTextPreference uses a layout with an EditText as this attribute.
May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
android:dialogMessage
android:dialogMessage
The message in the dialog. If a dialogLayout is provided and contains a TextView with ID android:id/message, this message will be placed in there.
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
android:dialogTitle
android:dialogTitle
The title in the dialog.
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
android:negativeButtonText
android:negativeButtonText
The negative button text for the dialog. Set to @null to hide the negative button.
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
android:positiveButtonText
android:positiveButtonText
The positive button text for the dialog. Set to @null to hide the positive button.
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
Sets the message of the dialog. This will be shown on subsequent dialogs.
This message forms the content View of the dialog and conflicts with list-based dialogs, for example. If setting a custom View on a dialog via setDialogLayoutResource(int), include a text View with ID android.R.id#message and it will be populated with this message.
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.
Shows the dialog associated with this Preference. This is normally initiated automatically on clicking on the preference. Call this method if you need to show the dialog on some other event.
Parameters
state
Bundle!: Optional instance state to restore on the dialog
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{
"last_modified": "Last updated 2024-04-11 UTC.",
"state": ""
}