public abstract class DialogPreference
extends Preference implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, PreferenceManager.OnActivityDestroyListener
| java.lang.Object | ||
| android.preference.Preference | ||
| android.preference.DialogPreference | ||
| |
基于对话框的Preference对象的基类。 点击后,这些首选项将打开一个对话框,显示实际的首选项控制。
XML attributes |
|
|---|---|
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. |
Inherited XML attributes |
|
|---|---|
android.preference.Preference
|
|
Inherited constants |
|---|
android.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) |
|
|---|---|
Dialog |
getDialog() 获取此首选项显示的对话框。 |
Drawable |
getDialogIcon() 返回后续对话框中显示的图标。 |
int |
getDialogLayoutResource() 返回用作后续对话框的内容视图的布局资源。 |
CharSequence |
getDialogMessage() 返回将在后续对话框中显示的消息。 |
CharSequence |
getDialogTitle() 返回后续对话框中显示的标题。 |
CharSequence |
getNegativeButtonText() 返回后续对话框中显示的否定按钮的文本。 |
CharSequence |
getPositiveButtonText() 返回在后续对话框中显示的肯定按钮的文本。 |
void |
onActivityDestroy() 请参阅活动的onDestroy。 |
void |
onClick(DialogInterface dialog, int which) 当单击对话框中的按钮时,将调用此方法。 |
void |
onDismiss(DialogInterface dialog) 该方法将在对话框关闭时调用。 |
void |
setDialogIcon(int dialogIconRes) 设置对话框的图标(资源ID)。 |
void |
setDialogIcon(Drawable dialogIcon) 设置对话框的图标。 |
void |
setDialogLayoutResource(int dialogLayoutResId) |
void |
setDialogMessage(CharSequence dialogMessage) 设置对话框的消息。 |
void |
setDialogMessage(int dialogMessageResId) |
void |
setDialogTitle(int dialogTitleResId) |
void |
setDialogTitle(CharSequence dialogTitle) 设置对话框的标题。 |
void |
setNegativeButtonText(CharSequence negativeButtonText) 设置对话框的负面按钮的文本。 |
void |
setNegativeButtonText(int negativeButtonTextResId) |
void |
setPositiveButtonText(int positiveButtonTextResId) |
void |
setPositiveButtonText(CharSequence positiveButtonText) 设置对话框的正面按钮的文本。 |
Protected methods |
|
|---|---|
void |
onBindDialogView(View view) 在数据对话框的内容视图中绑定视图。 |
void |
onClick() 处理点击偏好。 |
View |
onCreateDialogView() 创建对话框的内容视图(如果需要自定义内容视图)。 |
void |
onDialogClosed(boolean positiveResult) 当对话被解除时应该被调用,并且应该用于将数据保存到 |
void |
onPrepareDialogBuilder(AlertDialog.Builder builder) 准备在单击首选项时显示对话框构建器。 |
void |
onRestoreInstanceState(Parcelable state) 挂钩允许偏好重新应用其以前由 |
Parcelable |
onSaveInstanceState() 钩子允许首选项生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 |
void |
showDialog(Bundle state) 显示与此首选项关联的对话框。 |
继承方法(Inherited methods) |
|
|---|---|
android.preference.Preference
|
|
java.lang.Object
|
|
java.lang.Comparable
|
|
android.content.DialogInterface.OnClickListener
|
|
android.content.DialogInterface.OnDismissListener
|
|
android.preference.PreferenceManager.OnActivityDestroyListener
|
|
对话框的图标。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 dialogIcon 。
用作对话框的内容视图的布局。 默认情况下,这不应该需要。 如果需要自定义DialogPreference,则应该设置。 例如,EditTextPreference使用带有EditText的布局作为此属性。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 dialogLayout 。
对话框中的消息。 如果提供了dialogLayout并包含ID为android:id / message的TextView,则此消息将放置在那里。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 dialogMessage 。
对话框中的标题。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 dialogTitle 。
对话框的否定按钮文本。 设置为@null以隐藏负面按钮。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可以是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 negativeButtonText 。
对话框的正面按钮文本。 设置为@null以隐藏正面按钮。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 positiveButtonText 。
DialogPreference (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
defStyleRes |
int
|
DialogPreference (Context context, AttributeSet attrs, int defStyleAttr)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
DialogPreference (Context context, AttributeSet attrs)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
DialogPreference (Context context)
| 参数(Parameters) | |
|---|---|
context |
Context
|
Dialog getDialog ()
获取此首选项显示的对话框。
| 返回(Returns) | |
|---|---|
Dialog |
The dialog, or null if a dialog is not being shown. |
Drawable getDialogIcon ()
返回后续对话框中显示的图标。
| 返回(Returns) | |
|---|---|
Drawable |
The icon, as a Drawable. |
int getDialogLayoutResource ()
返回用作后续对话框的内容视图的布局资源。
| 返回(Returns) | |
|---|---|
int |
The layout resource. |
CharSequence getDialogMessage ()
返回将在后续对话框中显示的消息。
| 返回(Returns) | |
|---|---|
CharSequence |
The message. |
CharSequence getDialogTitle ()
返回后续对话框中显示的标题。
| 返回(Returns) | |
|---|---|
CharSequence |
The title. |
CharSequence getNegativeButtonText ()
返回后续对话框中显示的否定按钮的文本。
| 返回(Returns) | |
|---|---|
CharSequence |
The text of the negative button. |
CharSequence getPositiveButtonText ()
返回在后续对话框中显示的肯定按钮的文本。
| 返回(Returns) | |
|---|---|
CharSequence |
The text of the positive button. |
void onClick (DialogInterface dialog, int which)
当单击对话框中的按钮时,将调用此方法。
| 参数(Parameters) | |
|---|---|
dialog |
DialogInterface: The dialog that received the click. |
which |
int: The button that was clicked (e.g. BUTTON1) or the position of the item clicked. |
void onDismiss (DialogInterface dialog)
该方法将在对话框关闭时调用。
| 参数(Parameters) | |
|---|---|
dialog |
DialogInterface: The dialog that was dismissed will be passed into the method. |
void setDialogIcon (int dialogIconRes)
设置对话框的图标(资源ID)。 这将在随后的对话框中显示。
| 参数(Parameters) | |
|---|---|
dialogIconRes |
int: The icon, as a resource ID. |
void setDialogIcon (Drawable dialogIcon)
设置对话框的图标。 这将在随后的对话框中显示。
| 参数(Parameters) | |
|---|---|
dialogIcon |
Drawable: The icon, as a Drawable. |
void setDialogLayoutResource (int dialogLayoutResId)
将作为 View充气布局资源设置为后续对话框的内容视图。
| 参数(Parameters) | |
|---|---|
dialogLayoutResId |
int: The layout resource ID to be inflated. |
void setDialogMessage (CharSequence dialogMessage)
设置对话框的消息。 这将在随后的对话框中显示。
例如,此消息形成对话框的内容视图并与基于列表的对话框发生冲突。 如果通过setDialogLayoutResource(int)在对话框上设置自定义视图,请包含一个文本视图,其ID为message ,并且将填充此消息。
| 参数(Parameters) | |
|---|---|
dialogMessage |
CharSequence: The message. |
void setDialogMessage (int dialogMessageResId)
| 参数(Parameters) | |
|---|---|
dialogMessageResId |
int: The dialog message as a resource. |
void setDialogTitle (int dialogTitleResId)
| 参数(Parameters) | |
|---|---|
dialogTitleResId |
int: The dialog title as a resource. |
也可以看看:
void setDialogTitle (CharSequence dialogTitle)
设置对话框的标题。 这将在随后的对话框中显示。
| 参数(Parameters) | |
|---|---|
dialogTitle |
CharSequence: The title. |
void setNegativeButtonText (CharSequence negativeButtonText)
设置对话框的负面按钮的文本。 这将在随后的对话框中显示。
| 参数(Parameters) | |
|---|---|
negativeButtonText |
CharSequence: The text of the negative button. |
void setNegativeButtonText (int negativeButtonTextResId)
| 参数(Parameters) | |
|---|---|
negativeButtonTextResId |
int: The negative button text as a resource. |
void setPositiveButtonText (int positiveButtonTextResId)
| 参数(Parameters) | |
|---|---|
positiveButtonTextResId |
int: The positive button text as a resource. |
void setPositiveButtonText (CharSequence positiveButtonText)
设置对话框的正面按钮的文本。 这将在随后的对话框中显示。
| 参数(Parameters) | |
|---|---|
positiveButtonText |
CharSequence: The text of the positive button. |
void onBindDialogView (View view)
在数据对话框的内容视图中绑定视图。
确保通过超类实现进行调用。
| 参数(Parameters) | |
|---|---|
view |
View: The content View of the dialog, if it is custom. |
void onClick ()
处理点击偏好。 这包括将值保存到SharedPreferences 。 但是,重写的方法应该调用callChangeListener(Object)以确保客户端想要用新值更新首选项的状态。
View onCreateDialogView ()
创建对话框的内容视图(如果需要自定义内容视图)。 默认情况下,如果设置了对话框布局资源,它将膨胀。
| 返回(Returns) | |
|---|---|
View |
The content View for the dialog. |
也可以看看:
void onDialogClosed (boolean positiveResult)
当对话框被解除并且应该用于将数据保存到 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
positiveResult |
boolean: Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false). |
void onPrepareDialogBuilder (AlertDialog.Builder builder)
准备在单击首选项时显示对话框构建器。 使用它在对话框上设置自定义属性。
| 参数(Parameters) | |
|---|---|
builder |
AlertDialog.Builder
|
void onRestoreInstanceState (Parcelable state)
Hook允许偏好重新应用以前由onSaveInstanceState()生成的内部状态的表示。 这个函数永远不会被调用为null状态。
| 参数(Parameters) | |
|---|---|
state |
Parcelable: The saved state that had previously been returned by onSaveInstanceState(). |
Parcelable onSaveInstanceState ()
钩子允许首选项生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 这个状态应该只包含不持久的或者稍后可以重建的信息。
| 返回(Returns) | |
|---|---|
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. |
void showDialog (Bundle state)
显示与此首选项关联的对话框。 这通常在点击首选项时自动启动。 如果您需要在某些其他事件上显示对话框,请调用此方法。
| 参数(Parameters) | |
|---|---|
state |
Bundle: Optional instance state to restore on the dialog |