public abstract class TwoStatePreference
extends Preference
| java.lang.Object | ||
| android.preference.Preference | ||
| android.preference.TwoStatePreference | ||
| |
具有两种可选状态的首选项的公共基类,在SharedPreferences中保留布尔值,并且可能具有根据当前状态启用/禁用的相关首选项。
Inherited XML attributes |
|
|---|---|
android.preference.Preference
|
|
Inherited constants |
|---|
android.preference.Preference
|
Public constructors |
|
|---|---|
TwoStatePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) |
|
TwoStatePreference(Context context, AttributeSet attrs, int defStyleAttr) |
|
TwoStatePreference(Context context, AttributeSet attrs) |
|
TwoStatePreference(Context context) |
|
公共方法(Public methods) |
|
|---|---|
boolean |
getDisableDependentsState() 返回此首选项开启时是否禁用家属( |
CharSequence |
getSummaryOff() 返回未选中时显示的摘要。 |
CharSequence |
getSummaryOn() 返回选中时显示的摘要。 |
boolean |
isChecked() 返回检查的状态。 |
void |
setChecked(boolean checked) 设置选中的状态并将其保存到 |
void |
setDisableDependentsState(boolean disableDependentsState) 设置此首选项开启时是否禁用家属( |
void |
setSummaryOff(CharSequence summary) 设置未选中时显示的摘要。 |
void |
setSummaryOff(int summaryResId) |
void |
setSummaryOn(int summaryResId) |
void |
setSummaryOn(CharSequence summary) 设置选中时显示的摘要。 |
boolean |
shouldDisableDependents() 检查当前是否应该禁用此首选项的依赖项。 |
Protected methods |
|
|---|---|
void |
onClick() 处理点击偏好。 |
Object |
onGetDefaultValue(TypedArray a, int index) 当首选项被夸大并且需要读取默认值属性时调用。 |
void |
onRestoreInstanceState(Parcelable state) Hook允许偏好重新应用以前由 |
Parcelable |
onSaveInstanceState() 钩子允许首选项生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 |
void |
onSetInitialValue(boolean restoreValue, Object defaultValue) 执行此操作来设置首选项的初始值。 |
继承方法(Inherited methods) |
|
|---|---|
android.preference.Preference
|
|
java.lang.Object
|
|
java.lang.Comparable
|
|
TwoStatePreference (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
defStyleRes |
int
|
TwoStatePreference (Context context, AttributeSet attrs, int defStyleAttr)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
TwoStatePreference (Context context, AttributeSet attrs)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
TwoStatePreference (Context context)
| 参数(Parameters) | |
|---|---|
context |
Context
|
boolean getDisableDependentsState ()
返回当此首选项打开时( true )或此首选项关闭时是否禁用家属( false )。
| 返回(Returns) | |
|---|---|
boolean |
Whether dependents are disabled when this preference is on (true) or when this preference is off (false). |
CharSequence getSummaryOff ()
返回未选中时显示的摘要。
| 返回(Returns) | |
|---|---|
CharSequence |
The summary. |
CharSequence getSummaryOn ()
返回选中时显示的摘要。
| 返回(Returns) | |
|---|---|
CharSequence |
The summary. |
void setChecked (boolean checked)
设置选中状态并将其保存到 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
checked |
boolean: The checked state. |
void setDisableDependentsState (boolean disableDependentsState)
设置当此首选项打开时( true )还是此首选项关闭时( false ),是否禁用了依赖 false 。
| 参数(Parameters) | |
|---|---|
disableDependentsState |
boolean: The preference state that should disable dependents. |
void setSummaryOff (CharSequence summary)
设置未选中时显示的摘要。
| 参数(Parameters) | |
|---|---|
summary |
CharSequence: The summary to be shown when unchecked. |
void setSummaryOff (int summaryResId)
| 参数(Parameters) | |
|---|---|
summaryResId |
int: The summary as a resource. |
也可以看看:
void setSummaryOn (int summaryResId)
| 参数(Parameters) | |
|---|---|
summaryResId |
int: The summary as a resource. |
也可以看看:
void setSummaryOn (CharSequence summary)
设置选中时显示的摘要。
| 参数(Parameters) | |
|---|---|
summary |
CharSequence: The summary to be shown when checked. |
boolean shouldDisableDependents ()
检查当前是否应该禁用此首选项的依赖项。
| 返回(Returns) | |
|---|---|
boolean |
True if the dependents should be disabled, otherwise false. |
void onClick ()
处理点击偏好。 这包括将值保存到SharedPreferences 。 但是,重写的方法应该调用callChangeListener(Object)以确保客户端想要用新值更新首选项的状态。
Object onGetDefaultValue (TypedArray a, int index)
当首选项被夸大并且需要读取默认值属性时调用。 由于不同的首选项类型具有不同的值类型,因此子类应获取并返回默认值,该默认值将是其值类型。
例如,如果值类型为String,则该方法的主体将代理为 getString(int) 。
| 参数(Parameters) | |
|---|---|
a |
TypedArray: The set of attributes. |
index |
int: The index of the default value attribute. |
| 返回(Returns) | |
|---|---|
Object |
The default value of this preference type. |
void onRestoreInstanceState (Parcelable state)
钩子允许偏好重新应用其以前由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 onSetInitialValue (boolean restoreValue,
Object defaultValue)
执行此操作来设置首选项的初始值。
如果restorePersistedValue为true,则应从SharedPreferences恢复首选项值。 如果restorePersistedValue为false,则应将Preference值设置为给定的defaultValue(并且如果shouldPersist()为true,则可能shouldPersist()其存储到SharedPreferences中)。
这可能并不总是被称为。 一个例子是,如果它不应该坚持,但没有给出默认值。
| 参数(Parameters) | |
|---|---|
restoreValue |
boolean: True to restore the persisted value; false to use the given defaultValue. |
defaultValue |
Object: The default value for this Preference. Only use this if restorePersistedValue is false. |