Android APIs
public abstract class

DialogPreference

extends Preference
java.lang.Object
   ↳ android.support.v7.preference.Preference
     ↳ android.support.v7.preference.DialogPreference
Known Direct Subclasses

Class Overview

A base class for Preference objects that are dialog-based. These preferences will, when clicked, open a dialog showing the actual preference controls.

Summary

Nested Classes
interface DialogPreference.TargetFragment  
XML Attributes
Attribute Name Related Method Description
android:dialogIcon The icon for the dialog. 
android:dialogLayout A layout to be used as the content View for the dialog. 
android:dialogMessage The message in the dialog. 
android:dialogTitle The title in the dialog. 
android:negativeButtonText The negative button text for the dialog. 
android:positiveButtonText The positive button text for the dialog. 
[Expand]
Inherited XML Attributes
From class android.support.v7.preference.Preference
[Expand]
Inherited Constants
From class android.support.v7.preference.Preference
Public Constructors
DialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
DialogPreference(Context context, AttributeSet attrs, int defStyleAttr)
DialogPreference(Context context, AttributeSet attrs)
DialogPreference(Context context)
Public Methods
Drawable getDialogIcon()
Returns the icon to be shown on subsequent dialogs.
int getDialogLayoutResource()
Returns the layout resource that is used as the content View for subsequent dialogs.
CharSequence getDialogMessage()
Returns the message to be shown on subsequent dialogs.
CharSequence getDialogTitle()
Returns the title to be shown on subsequent dialogs.
CharSequence getNegativeButtonText()
Returns the text of the negative button to be shown on subsequent dialogs.
CharSequence getPositiveButtonText()
Returns the text of the positive button to be shown on subsequent dialogs.
void setDialogIcon(int dialogIconRes)
Sets the icon (resource ID) of the dialog.
void setDialogIcon(Drawable dialogIcon)
Sets the icon of the dialog.
void setDialogLayoutResource(int dialogLayoutResId)
Sets the layout resource that is inflated as the View to be shown as the content View of subsequent dialogs.
void setDialogMessage(CharSequence dialogMessage)
Sets the message of the dialog.
void setDialogMessage(int dialogMessageResId)
void setDialogTitle(int dialogTitleResId)
void setDialogTitle(CharSequence dialogTitle)
Sets the title of the dialog.
void setNegativeButtonText(int negativeButtonTextResId)
void setNegativeButtonText(CharSequence negativeButtonText)
Sets the text of the negative button of the dialog.
void setPositiveButtonText(int positiveButtonTextResId)
void setPositiveButtonText(CharSequence positiveButtonText)
Sets the text of the positive button of the dialog.
Protected Methods
void onClick()
Processes a click on the preference.
[Expand]
Inherited Methods
From class android.support.v7.preference.Preference
From class java.lang.Object
From interface java.lang.Comparable

XML Attributes

android:dialogIcon

The icon for the dialog.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol dialogIcon.

Related Methods

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.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol dialogLayout.

Related Methods

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.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol dialogMessage.

Related Methods

android:dialogTitle

The title in the dialog.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol dialogTitle.

Related Methods

android:negativeButtonText

The negative button text for the dialog. Set to @null to hide the negative button.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol negativeButtonText.

Related Methods

android:positiveButtonText

The positive button text for the dialog. Set to @null to hide the positive button.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol positiveButtonText.

Related Methods

Public Constructors

public DialogPreference (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

public DialogPreference (Context context, AttributeSet attrs, int defStyleAttr)

public DialogPreference (Context context, AttributeSet attrs)

public DialogPreference (Context context)

Public Methods

public Drawable getDialogIcon ()

Returns the icon to be shown on subsequent dialogs.

Returns

public int getDialogLayoutResource ()

Returns the layout resource that is used as the content View for subsequent dialogs.

Returns
  • The layout resource.

public CharSequence getDialogMessage ()

Returns the message to be shown on subsequent dialogs.

Returns
  • The message.

public CharSequence getDialogTitle ()

Returns the title to be shown on subsequent dialogs.

Returns
  • The title.

public CharSequence getNegativeButtonText ()

Returns the text of the negative button to be shown on subsequent dialogs.

Returns
  • The text of the negative button.

public CharSequence getPositiveButtonText ()

Returns the text of the positive button to be shown on subsequent dialogs.

Returns
  • The text of the positive button.

public void setDialogIcon (int dialogIconRes)

Sets the icon (resource ID) of the dialog. This will be shown on subsequent dialogs.

Parameters
dialogIconRes The icon, as a resource ID.

public void setDialogIcon (Drawable dialogIcon)

Sets the icon of the dialog. This will be shown on subsequent dialogs.

Parameters
dialogIcon The icon, as a Drawable.

public void setDialogLayoutResource (int dialogLayoutResId)

Sets the layout resource that is inflated as the View to be shown as the content View of subsequent dialogs.

Parameters
dialogLayoutResId The layout resource ID to be inflated.

public void setDialogMessage (CharSequence dialogMessage)

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 message and it will be populated with this message.

Parameters
dialogMessage The message.

public void setDialogMessage (int dialogMessageResId)

Parameters
dialogMessageResId The dialog message as a resource.

public void setDialogTitle (int dialogTitleResId)

Parameters
dialogTitleResId The dialog title as a resource.

public void setDialogTitle (CharSequence dialogTitle)

Sets the title of the dialog. This will be shown on subsequent dialogs.

Parameters
dialogTitle The title.

public void setNegativeButtonText (int negativeButtonTextResId)

Parameters
negativeButtonTextResId The negative button text as a resource.

public void setNegativeButtonText (CharSequence negativeButtonText)

Sets the text of the negative button of the dialog. This will be shown on subsequent dialogs.

Parameters
negativeButtonText The text of the negative button.

public void setPositiveButtonText (int positiveButtonTextResId)

Parameters
positiveButtonTextResId The positive button text as a resource.

public void setPositiveButtonText (CharSequence positiveButtonText)

Sets the text of the positive button of the dialog. This will be shown on subsequent dialogs.

Parameters
positiveButtonText The text of the positive button.

Protected Methods

protected void onClick ()

Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call callChangeListener(Object) to make sure the client wants to update the preference's state with the new value.