public class Preference
extends Object implements Comparable<Preference>
| java.lang.Object | |
| android.preference.Preference | |
| |
| |
表示由显示的基本偏好UI积木PreferenceActivity在一个形式ListView 。 此课程提供View以显示在活动中并与SharedPreferences相关联以存储/检索首选项数据。
在XML中指定偏好层次结构时,每个元素都可以指向 Preference的子类,与视图层次结构和布局类似。
这个类包含一个key ,它将被用作SharedPreferences 。 由子类决定如何存储该值。
有关使用首选项构建设置UI的信息,请阅读 Settings指南。
Nested classes |
|
|---|---|
class |
Preference.BaseSavedState 用于管理 |
interface |
Preference.OnPreferenceChangeListener 当用户更改了此 |
interface |
Preference.OnPreferenceClickListener 单击 |
XML attributes |
|
|---|---|
android:defaultValue |
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. |
android:dependency |
The key of another Preference that this Preference will depend on. |
android:enabled |
Whether the Preference is enabled. |
android:fragment |
When used inside of a modern PreferenceActivity, this declares a new PreferenceFragment to be shown when the user selects this item. |
android:icon |
The optional icon for the preference 必须是另一个资源的引用,其形式为“ |
android:key |
The key to store the Preference value. |
android:layout |
The layout for the Preference in a PreferenceActivity screen. |
android:order |
The order for the Preference (lower values are to be ordered first). |
android:persistent |
Whether the Preference stores its value to the shared preferences. |
android:selectable |
Whether the Preference is selectable. |
android:shouldDisableView |
Whether the view of this Preference should be disabled when this Preference is disabled. |
android:summary |
The summary for the Preference in a PreferenceActivity screen. |
android:title |
The title for the Preference in a PreferenceActivity screen. |
android:widgetLayout |
The layout for the controllable widget portion of a Preference. |
常量(Constants) |
|
|---|---|
int |
DEFAULT_ORDER 如果不需要特定的订单,请指定 |
Public constructors |
|
|---|---|
Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) 从XML执行通货膨胀并应用特定于类的基本样式。 |
|
Preference(Context context, AttributeSet attrs, int defStyleAttr) 从XML执行通货膨胀并应用特定于类的基本样式。 |
|
Preference(Context context, AttributeSet attrs) 从XML扩展偏好时调用的构造函数。 |
|
Preference(Context context) 构造函数创建首选项。 |
|
公共方法(Public methods) |
|
|---|---|
int |
compareTo(Preference another) 根据订单(如果设置)比较偏好对象,否则按标题按字母顺序排列。 |
Context |
getContext() 返回此首选项的 |
String |
getDependency() 返回此首选项的依赖项的关键。 |
SharedPreferences.Editor |
getEditor() 返回此首选项可以保存其值的 |
Bundle |
getExtras() 返回与此首选项关联的额外Bundle对象,如果当前不存在Bundle对象,则创建一个新Bundle。 |
String |
getFragment() 返回与此首选项关联的片段类名称。 |
Drawable |
getIcon() 返回此首选项的图标。 |
Intent |
getIntent() 返回与此首选项关联的 |
String |
getKey() 获取此首选项的关键字,这也是用于将值存储到SharedPreferences中的关键。 |
int |
getLayoutResource() 获取此首选项将显示为 |
Preference.OnPreferenceChangeListener |
getOnPreferenceChangeListener() 当用户更改此首选项时(但内部状态已更新之前),返回要调用的回调。 |
Preference.OnPreferenceClickListener |
getOnPreferenceClickListener() 返回单击此首选项时要调用的回调。 |
int |
getOrder() 获取此Preference相对于同一级别上的其他Preference对象的顺序。 |
Set<String> |
getPersistedStringSet(Set<String> defaultReturnValue) 尝试从 |
PreferenceManager |
getPreferenceManager() 获取管理此首选项对象树的 |
SharedPreferences |
getSharedPreferences() 返回此首选项可以读取其值的 |
boolean |
getShouldDisableView() 检查此首选项是否应在其操作处于禁用状态时禁用其视图。 |
CharSequence |
getSummary() 返回此首选项的摘要。 |
CharSequence |
getTitle() 返回此首选项的标题。 |
int |
getTitleRes() 返回此首选项的标题资源ID。 |
View |
getView(View convertView, ViewGroup parent) 获取将显示在 |
int |
getWidgetLayoutResource() 获取此首选项的可控小部件的布局资源。 |
boolean |
hasKey() 检查此首选项是否有有效的密钥。 |
boolean |
isEnabled() 检查此首选项是否应在列表中启用。 |
boolean |
isPersistent() 检查此首选项是否持久。 |
boolean |
isSelectable() 检查此首选项是否应该在列表中可选。 |
void |
notifyDependencyChange(boolean disableDependents) 通知任何监听依赖者影响依赖性的更改。 |
void |
onDependencyChanged(Preference dependency, boolean disableDependent) 当依赖关系发生变化时调用。 |
void |
onParentChanged(Preference parent, boolean disableChild) 当隐式父依赖性发生变化时调用。 |
Bundle |
peekExtras() 返回与此首选项关联的额外Bundle对象,如果当前不存在返回null。 |
boolean |
persistStringSet(Set<String> values) 尝试将一组字符串保存到 |
void |
restoreHierarchyState(Bundle container) 从给定的容器中恢复此首选项层次结构的先前保存的状态。 |
void |
saveHierarchyState(Bundle container) 将此首选项层次结构的冻结状态存储到给定的容器中。 |
void |
setDefaultValue(Object defaultValue) 设置此首选项的默认值,如果持久性处于关闭状态或持久性处于打开状态并且在持久性存储器中未找到首选项,则会设置该首选项。 |
void |
setDependency(String dependencyKey) 设置此首选项将依赖的首选项的关键。 |
void |
setEnabled(boolean enabled) 设置是否启用此首选项。 |
void |
setFragment(String fragment) 设置单击此首选项时要显示的片段的类名称。 |
void |
setIcon(Drawable icon) 使用Drawable设置此首选项的图标。 |
void |
setIcon(int iconResId) 使用资源ID设置此首选项的图标。 |
void |
setIntent(Intent intent) 单击此首选项时,将 |
void |
setKey(String key) 设置此首选项的密钥,该密钥用作 |
void |
setLayoutResource(int layoutResId) 将此首选项显示为 |
void |
setOnPreferenceChangeListener(Preference.OnPreferenceChangeListener onPreferenceChangeListener) 当用户更改此首选项时(但在内部状态更新之前)设置要调用的回调。 |
void |
setOnPreferenceClickListener(Preference.OnPreferenceClickListener onPreferenceClickListener) 设置单击此首选项时要调用的回调。 |
void |
setOrder(int order) 设置此首选项相对于同一级别上的其他首选项对象的顺序。 |
void |
setPersistent(boolean persistent) 设置此首选项是否持久。 |
void |
setSelectable(boolean selectable) 设置此首选项是否可选。 |
void |
setShouldDisableView(boolean shouldDisableView) 设置此首选项是否应禁用其视图。 |
void |
setSummary(CharSequence summary) 使用CharSequence设置此首选项的摘要。 |
void |
setSummary(int summaryResId) 使用资源ID设置此首选项的摘要。 |
void |
setTitle(CharSequence title) 使用CharSequence设置此首选项的标题。 |
void |
setTitle(int titleResId) 使用资源ID设置此首选项的标题。 |
void |
setWidgetLayoutResource(int widgetLayoutResId) 设置此首选项的可控件部分的布局。 |
boolean |
shouldCommit() 返回是否 |
boolean |
shouldDisableDependents() 检查当前是否应该禁用此首选项的依赖项。 |
String |
toString() 返回对象的字符串表示形式。 |
Protected methods |
|
|---|---|
boolean |
callChangeListener(Object newValue) 在用户更改首选项之后但在内部状态设置之前调用此方法。 |
Preference |
findPreferenceInHierarchy(String key) 使用给定的键找到此层次结构中的首选项(整个项目,甚至高于/低于 |
boolean |
getPersistedBoolean(boolean defaultReturnValue) 尝试从 |
float |
getPersistedFloat(float defaultReturnValue) 尝试从 |
int |
getPersistedInt(int defaultReturnValue) 尝试从 |
long |
getPersistedLong(long defaultReturnValue) 尝试从 |
String |
getPersistedString(String defaultReturnValue) 尝试从 |
void |
notifyChanged() 当这个 |
void |
notifyHierarchyChanged() 应该在从此组添加/移除偏好时调用,或者应该重新评估顺序。 |
void |
onAttachedToActivity() 当偏好层次结构已附加到 |
void |
onAttachedToHierarchy(PreferenceManager preferenceManager) 当此首选项已附加到首选项层次结构时调用。 |
void |
onBindView(View view) 将创建的视图绑定到此首选项的数据。 |
void |
onClick() 处理点击偏好。 |
View |
onCreateView(ViewGroup parent) 在 |
Object |
onGetDefaultValue(TypedArray a, int index) 当首选项被夸大并且需要读取默认值属性时调用。 |
void |
onPrepareForRemoval() 当此首选项从层次结构中删除时调用。 |
void |
onRestoreInstanceState(Parcelable state) 挂钩允许偏好重新应用以前由 |
Parcelable |
onSaveInstanceState() 钩子允许首选项生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 |
void |
onSetInitialValue(boolean restorePersistedValue, Object defaultValue) 执行此操作来设置首选项的初始值。 |
boolean |
persistBoolean(boolean value) 尝试将布尔值保存到 |
boolean |
persistFloat(float value) 尝试持续浮动到 |
boolean |
persistInt(int value) 试图持续int到 |
boolean |
persistLong(long value) 试图坚持长达 |
boolean |
persistString(String value) 尝试将字符串保存到 |
boolean |
shouldPersist() 检查是否在给定时间调用此方法时,此首选项应将其值存储/恢复到 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.lang.Comparable
|
|
首选项的默认值,将在持久性为关闭或持久性打开时设置,并且在持久性存储中未找到首选项。
可能是对“ @[+][package:]type:name ”形式的其他资源的引用,也可能是对“ @[+][package:]type:name ”形式的主题属性的 ?[package:][type:]name 。
可能是一个字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
可能是整数值,例如“ 100 ”。
可能是布尔值,可能是“ true ”或“ false ”。
可能是浮点值,例如“ 1.2 ”。
这对应于全局属性资源符号 defaultValue 。
这个偏好将取决于另一个偏好的关键。 如果其他首选项未设置或关闭,则此首选项将被禁用。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 dependency 。
首选项是否启用。
必须是布尔值,可以是“ true ”或“ false ”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 enabled 。
当在现代PreferenceActivity中使用时,它会声明一个新的PreferenceFragment,当用户选择这个项目时显示。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 fragment 。
首选项的可选图标
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 icon 。
存储首选项值的关键。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可以是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 key 。
PreferenceActivity屏幕中的首选项的布局。 这应该很少需要改变,而是看看widgetLayout。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 layout 。
偏好的顺序(较低的值将首先排序)。 如果没有指定,默认排序将按字母顺序排列。
必须是整数值,例如“ 100 ”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 order 。
首选项是否将其值存储到共享首选项中。
必须是布尔值,可以是“ true ”或“ false ”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 persistent 。
首选项是否可选。
必须是布尔值,可以是“ true ”或“ false ”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 selectable 。
此首选项禁用时是否应禁用此首选项的视图。
必须是布尔值,可以是“ true ”或“ false ”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 shouldDisableView 。
PreferenceActivity屏幕中的首选项摘要。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 summary 。
PreferenceActivity屏幕中的首选项的标题。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 title 。
偏好设置的可控件部分的布局。 这会扩展到Preference的布局,应该比布局属性更频繁地使用。 例如,复选框首选项将在此处指定自定义布局(仅由CheckBox组成)。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 widgetLayout 。
int DEFAULT_ORDER
如果不需要特定订单,请指定 setOrder(int) 。
常量值:2147483647(0x7fffffff)
Preference (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
从XML执行通货膨胀并应用特定于类的基本样式。 Preference的构造函数允许子类在充气时使用它们自己的基础样式。 例如,一个CheckBoxPreference构造函数调用此版本的超类构造函数,并为android.R.attr.checkBoxPreferenceStyle提供android.R.attr.checkBoxPreferenceStyle 。 这允许主题的复选框首选项样式修改所有基本首选项属性以及CheckBoxPreference类的属性。
| 参数(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 the theme. Can be 0 to not look for defaults. |
Preference (Context context, AttributeSet attrs, int defStyleAttr)
从XML执行通货膨胀并应用特定于类的基本样式。 Preference的构造函数允许子类在充气时使用它们自己的基础样式。 例如, CheckBoxPreference构造函数调用此版本的超类构造函数,并为android.R.attr.checkBoxPreferenceStyle提供android.R.attr.checkBoxPreferenceStyle 。 这使主题的复选框首选项样式可以修改所有基本首选项属性以及CheckBoxPreference类的属性。
| 参数(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. |
Preference (Context context, AttributeSet attrs)
从XML扩展偏好时调用的构造函数。 这是在从XML文件构造首选项时调用的,并提供在XML文件中指定的属性。 此版本使用默认样式0,所以应用的唯一属性值是Context's Theme和给定AttributeSet中的值。
| 参数(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. |
Preference (Context context)
构造函数创建首选项。
| 参数(Parameters) | |
|---|---|
context |
Context: The Context in which to store Preference values. |
int compareTo (Preference another)
根据订单(如果设置)比较偏好对象,否则按标题按字母顺序排列。
| 参数(Parameters) | |
|---|---|
another |
Preference: The Preference to compare to this one. |
| 返回(Returns) | |
|---|---|
int |
0 if the same; less than 0 if this Preference sorts ahead of another; greater than 0 if this Preference sorts after another. |
Context getContext ()
返回此首选项的Context 。 偏好层次结构中的每个偏好可以来自不同的上下文(例如,如果多个活动将偏好提供给单个PreferenceActivity )。 此上下文将用于保存偏好设置值。
| 返回(Returns) | |
|---|---|
Context |
The Context of this Preference. |
String getDependency ()
返回此首选项的依赖项的关键。
| 返回(Returns) | |
|---|---|
String |
The key of the dependency. |
也可以看看:
SharedPreferences.Editor getEditor ()
返回一个SharedPreferences.Editor ,其中此首选项可以保存其值(s)。 通常它更容易使用助手保存方法之一: persistBoolean(boolean) , persistFloat(float) , persistInt(int) , persistLong(long) , persistString(String) 。 要读取值,请参阅getSharedPreferences() 。 如果shouldCommit()返回true,则此首选项有责任提交。
在某些情况下,对此的写入不会立即提交,因此不会在SharedPreferences中显示,这是提高性能的预期行为。
| 返回(Returns) | |
|---|---|
SharedPreferences.Editor |
A SharedPreferences.Editor where this preference saves its value(s), or null if it isn't attached to a Preference hierarchy. |
Bundle getExtras ()
返回与此首选项关联的额外Bundle对象,如果当前不存在Bundle对象,则创建一个新Bundle。 您可以使用它来获取和设置单独的额外键/值对。
| 返回(Returns) | |
|---|---|
Bundle |
|
String getFragment ()
返回与此首选项关联的片段类名称。
| 返回(Returns) | |
|---|---|
String |
The fragment class name last set via setFragment(String) or XML. |
Intent getIntent ()
返回与此首选项关联的 Intent 。
| 返回(Returns) | |
|---|---|
Intent |
The Intent last set via setIntent(Intent) or XML. |
String getKey ()
获取此首选项的关键字,这也是用于将值存储到SharedPreferences中的关键。
| 返回(Returns) | |
|---|---|
String |
The key. |
int getLayoutResource ()
获取此首选项将显示为 View的布局资源。
| 返回(Returns) | |
|---|---|
int |
The layout resource ID. |
Preference.OnPreferenceChangeListener getOnPreferenceChangeListener ()
当用户更改此首选项时(但内部状态已更新之前),返回要调用的回调。
| 返回(Returns) | |
|---|---|
Preference.OnPreferenceChangeListener |
The callback to be invoked. |
Preference.OnPreferenceClickListener getOnPreferenceClickListener ()
返回单击此首选项时要调用的回调。
| 返回(Returns) | |
|---|---|
Preference.OnPreferenceClickListener |
The callback to be invoked. |
int getOrder ()
获取此Preference相对于同一级别上的其他Preference对象的顺序。
| 返回(Returns) | |
|---|---|
int |
The order of this Preference. |
也可以看看:
Set<String> getPersistedStringSet (Set<String> defaultReturnValue)
尝试从 SharedPreferences获取一组持续的字符串。
这将检查此首选项是否持久,从 PreferenceManager获取SharedPreferences,并获取该值。
| 参数(Parameters) | |
|---|---|
defaultReturnValue |
Set: The default value to return if either the Preference is not persistent or the Preference is not in the shared preferences. |
| 返回(Returns) | |
|---|---|
Set<String> |
The value from the SharedPreferences or the default return value. |
也可以看看:
PreferenceManager getPreferenceManager ()
获取管理此首选项对象树的 PreferenceManager 。
| 返回(Returns) | |
|---|---|
PreferenceManager |
The PreferenceManager. |
SharedPreferences getSharedPreferences ()
返回此首选项可以读取其值的SharedPreferences 。 通常情况下,它更容易使用的辅助阅读方法之一: getPersistedBoolean(boolean) , getPersistedFloat(float) , getPersistedInt(int) , getPersistedLong(long) , getPersistedString(String) 。 要保存值,请参阅getEditor() 。
在某些情况下,写入 getEditor()不会立即提交,因此不会在返回的 SharedPreferences ,这是旨在提高性能的预期行为。
| 返回(Returns) | |
|---|---|
SharedPreferences |
The SharedPreferences where this Preference reads its value(s), or null if it isn't attached to a Preference hierarchy. |
也可以看看:
boolean getShouldDisableView ()
检查此首选项是否应在其操作处于禁用状态时禁用其视图。
| 返回(Returns) | |
|---|---|
boolean |
True if it should disable the view. |
CharSequence getSummary ()
返回此首选项的摘要。
| 返回(Returns) | |
|---|---|
CharSequence |
The summary. |
也可以看看:
CharSequence getTitle ()
返回此首选项的标题。
| 返回(Returns) | |
|---|---|
CharSequence |
The title. |
也可以看看:
int getTitleRes ()
返回此首选项的标题资源ID。 如果标题不是来自资源,则返回0。
| 返回(Returns) | |
|---|---|
int |
The title resource. |
也可以看看:
View getView (View convertView, ViewGroup parent)
获取将显示在 PreferenceActivity中的 PreferenceActivity 。
| 参数(Parameters) | |
|---|---|
convertView |
View: The old View to reuse, if possible. Note: You should check that this View is non-null and of an appropriate type before using. If it is not possible to convert this View to display the correct data, this method can create a new View. |
parent |
ViewGroup: The parent that this View will eventually be attached to. |
| 返回(Returns) | |
|---|---|
View |
Returns the same Preference object, for chaining multiple calls into a single statement. |
int getWidgetLayoutResource ()
获取此首选项的可控小部件的布局资源。
| 返回(Returns) | |
|---|---|
int |
The layout resource ID. |
boolean hasKey ()
检查此首选项是否有有效的密钥。
| 返回(Returns) | |
|---|---|
boolean |
True if the key exists and is not a blank string, false otherwise. |
boolean isEnabled ()
检查此首选项是否应在列表中启用。
| 返回(Returns) | |
|---|---|
boolean |
True if this Preference is enabled, false otherwise. |
boolean isPersistent ()
检查此首选项是否持久。 如果是,则将其值存储到持久SharedPreferences存储中。
| 返回(Returns) | |
|---|---|
boolean |
True if it is persistent. |
boolean isSelectable ()
检查此首选项是否应该在列表中可选。
| 返回(Returns) | |
|---|---|
boolean |
True if it is selectable, false otherwise. |
void notifyDependencyChange (boolean disableDependents)
通知任何监听依赖者影响依赖性的更改。
| 参数(Parameters) | |
|---|---|
disableDependents |
boolean: Whether this Preference should disable its dependents. |
void onDependencyChanged (Preference dependency, boolean disableDependent)
当依赖关系发生变化时调用。
| 参数(Parameters) | |
|---|---|
dependency |
Preference: The Preference that this Preference depends on. |
disableDependent |
boolean: Set true to disable this Preference. |
void onParentChanged (Preference parent, boolean disableChild)
当隐式父依赖性发生变化时调用。
| 参数(Parameters) | |
|---|---|
parent |
Preference: The Preference that this Preference depends on. |
disableChild |
boolean: Set true to disable this Preference. |
Bundle peekExtras ()
返回与此首选项关联的额外Bundle对象,如果当前不存在返回null。
| 返回(Returns) | |
|---|---|
Bundle |
|
boolean persistStringSet (Set<String> values)
尝试将一组字符串保存到 SharedPreferences 。
这将检查此Preference是否持久,从 PreferenceManager获取编辑器,放入字符串,并检查是否应该提交(如果是,则提交)。
| 参数(Parameters) | |
|---|---|
values |
Set: The values to persist. |
| 返回(Returns) | |
|---|---|
boolean |
True if the Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) |
也可以看看:
void restoreHierarchyState (Bundle container)
从给定的容器中恢复此首选项层次结构的先前保存的状态。
| 参数(Parameters) | |
|---|---|
container |
Bundle: The Bundle that holds the previously saved state. |
void saveHierarchyState (Bundle container)
将此首选项层次结构的冻结状态存储到给定的容器中。
| 参数(Parameters) | |
|---|---|
container |
Bundle: The Bundle in which to save the instance of this Preference. |
void setDefaultValue (Object defaultValue)
设置此首选项的默认值,如果持久性处于关闭状态或持久性处于打开状态并且在持久性存储器中未找到首选项,则会设置该首选项。
| 参数(Parameters) | |
|---|---|
defaultValue |
Object: The default value. |
void setDependency (String dependencyKey)
设置此首选项将依赖的首选项的关键。 如果该首选项未设置或关闭,则此首选项将被禁用。
| 参数(Parameters) | |
|---|---|
dependencyKey |
String: The key of the Preference that this depends on. |
void setEnabled (boolean enabled)
设置是否启用此首选项。 如果禁用,则不会处理点击。
| 参数(Parameters) | |
|---|---|
enabled |
boolean: Set true to enable it. |
void setFragment (String fragment)
设置单击此首选项时要显示的片段的类名称。
| 参数(Parameters) | |
|---|---|
fragment |
String: The class name of the fragment associated with this Preference. |
void setIcon (Drawable icon)
使用Drawable设置此首选项的图标。 此图标将放入由onCreateView(ViewGroup)创建的视图中的ID icon中。
| 参数(Parameters) | |
|---|---|
icon |
Drawable: The optional icon for this Preference. |
void setIcon (int iconResId)
使用资源ID设置此首选项的图标。
| 参数(Parameters) | |
|---|---|
iconResId |
int: The icon as a resource ID. |
也可以看看:
void setIntent (Intent intent)
单击此首选项时,将 Intent设置为 startActivity(Intent) 。
| 参数(Parameters) | |
|---|---|
intent |
Intent: The intent associated with this Preference. |
void setKey (String key)
设置此首选项的密钥,该密钥用作SharedPreferences的密钥。 这对于包装应该是独一无二的。
| 参数(Parameters) | |
|---|---|
key |
String: The key for the preference. |
void setLayoutResource (int layoutResId)
将此首选项设置为要显示的View充气布局资源。 在大多数情况下,默认布局对于自定义首选项对象是足够的,只有小部件布局需要更改。
这种布局应该包含ViewGroup ID为widget_frame成为这种偏好的特定部件的父。 它应该同样包含title和summary 。
| 参数(Parameters) | |
|---|---|
layoutResId |
int: The layout resource ID to be inflated and returned as a View. |
也可以看看:
void setOnPreferenceChangeListener (Preference.OnPreferenceChangeListener onPreferenceChangeListener)
当用户更改此首选项时(但在内部状态更新之前)设置要调用的回调。
| 参数(Parameters) | |
|---|---|
onPreferenceChangeListener |
Preference.OnPreferenceChangeListener: The callback to be invoked. |
void setOnPreferenceClickListener (Preference.OnPreferenceClickListener onPreferenceClickListener)
设置单击此首选项时要调用的回调。
| 参数(Parameters) | |
|---|---|
onPreferenceClickListener |
Preference.OnPreferenceClickListener: The callback to be invoked. |
void setOrder (int order)
设置此首选项相对于同一级别上的其他首选项对象的顺序。 如果没有指定,默认行为是按字母顺序排序。 setOrderingAsAdded(boolean)可用于根据它们在XML中出现的顺序对Preference对象进行排序。
| 参数(Parameters) | |
|---|---|
order |
int: The order for this Preference. A lower value will be shown first. Use DEFAULT_ORDER to sort alphabetically or allow ordering from XML. |
void setPersistent (boolean persistent)
设置此首选项是否持久。 当持续的,它存储的值(S)为持久SharedPreferences存储。
| 参数(Parameters) | |
|---|---|
persistent |
boolean: Set true if it should store its value(s) into the SharedPreferences. |
void setSelectable (boolean selectable)
设置此首选项是否可选。
| 参数(Parameters) | |
|---|---|
selectable |
boolean: Set true to make it selectable. |
void setShouldDisableView (boolean shouldDisableView)
设置此首选项是否应禁用其视图。
例如,对于仅显示信息的首选项,将此设为 setEnabled(boolean)为false,并且1)不应该可点击2)不应将视图设置为禁用状态。
| 参数(Parameters) | |
|---|---|
shouldDisableView |
boolean: Set true if this preference should disable its view when the preference is disabled. |
void setSummary (CharSequence summary)
使用CharSequence设置此首选项的摘要。
| 参数(Parameters) | |
|---|---|
summary |
CharSequence: The summary for the preference. |
void setSummary (int summaryResId)
使用资源ID设置此首选项的摘要。
| 参数(Parameters) | |
|---|---|
summaryResId |
int: The summary as a resource. |
也可以看看:
void setTitle (CharSequence title)
使用CharSequence设置此首选项的标题。 此标题将被放置在由onCreateView(ViewGroup)创建的视图中的ID title中。
| 参数(Parameters) | |
|---|---|
title |
CharSequence: The title for this Preference. |
void setTitle (int titleResId)
使用资源ID设置此首选项的标题。
| 参数(Parameters) | |
|---|---|
titleResId |
int: The title as a resource ID. |
也可以看看:
void setWidgetLayoutResource (int widgetLayoutResId)
设置此首选项的可控件部分的布局。 这是膨胀到主布局。 例如, CheckBoxPreference会在这里指定自定义布局(仅由CheckBox组成),而不是创建自己的主布局。
| 参数(Parameters) | |
|---|---|
widgetLayoutResId |
int: The layout resource ID to be inflated into the main layout. |
也可以看看:
boolean shouldCommit ()
返回是否Preference应提交其保存的值(一个或多个) getEditor() 。 在批次提交(经理)完成以提高性能的情况下,这可能会返回错误。
| 返回(Returns) | |
|---|---|
boolean |
Whether the Preference should commit its saved value(s). |
也可以看看:
boolean shouldDisableDependents ()
检查当前是否应该禁用此首选项的依赖项。
| 返回(Returns) | |
|---|---|
boolean |
True if the dependents should be disabled, otherwise false. |
String toString ()
返回对象的字符串表示形式。 通常, toString方法会返回一个“文本地表示”该对象的字符串。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。
类Object的toString方法返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”和对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| 返回(Returns) | |
|---|---|
String |
a string representation of the object. |
boolean callChangeListener (Object newValue)
在用户更改首选项之后但在内部状态设置之前调用此方法。 这允许客户端忽略用户值。
| 参数(Parameters) | |
|---|---|
newValue |
Object: The new value of this Preference. |
| 返回(Returns) | |
|---|---|
boolean |
True if the user value should be set as the preference value (and persisted). |
Preference findPreferenceInHierarchy (String key)
使用给定的键在此层次结构中找到首选项(整个项目,甚至高于/低于 PreferenceScreen屏幕截图)。
这只在我们被附加到层次结构后才起作用。
| 参数(Parameters) | |
|---|---|
key |
String: The key of the Preference to find. |
| 返回(Returns) | |
|---|---|
Preference |
The Preference that uses the given key. |
boolean getPersistedBoolean (boolean defaultReturnValue)
尝试从 SharedPreferences获取持久布尔值。
| 参数(Parameters) | |
|---|---|
defaultReturnValue |
boolean: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. |
| 返回(Returns) | |
|---|---|
boolean |
The value from the SharedPreferences or the default return value. |
float getPersistedFloat (float defaultReturnValue)
尝试从 SharedPreferences获得持续浮动。
| 参数(Parameters) | |
|---|---|
defaultReturnValue |
float: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. |
| 返回(Returns) | |
|---|---|
float |
The value from the SharedPreferences or the default return value. |
int getPersistedInt (int defaultReturnValue)
尝试从 SharedPreferences获取持久化int。
| 参数(Parameters) | |
|---|---|
defaultReturnValue |
int: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. |
| 返回(Returns) | |
|---|---|
int |
The value from the SharedPreferences or the default return value. |
long getPersistedLong (long defaultReturnValue)
尝试从 SharedPreferences获得持续很长的 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
defaultReturnValue |
long: The default value to return if either this Preference is not persistent or this Preference is not in the SharedPreferences. |
| 返回(Returns) | |
|---|---|
long |
The value from the SharedPreferences or the default return value. |
String getPersistedString (String defaultReturnValue)
尝试从 SharedPreferences获取持久字符串。
这将检查此首选项是否持久,从 PreferenceManager获取SharedPreferences,并获取该值。
| 参数(Parameters) | |
|---|---|
defaultReturnValue |
String: The default value to return if either the Preference is not persistent or the Preference is not in the shared preferences. |
| 返回(Returns) | |
|---|---|
String |
The value from the SharedPreferences or the default return value. |
也可以看看:
void notifyHierarchyChanged ()
应该在从此组添加/移除偏好时调用,或者应该重新评估顺序。
void onAttachedToActivity ()
当偏好层次结构已附加到PreferenceActivity 。 当此首选项已附加到已连接到PreferenceActivity的组时,也可以调用此选项。
void onAttachedToHierarchy (PreferenceManager preferenceManager)
当此首选项已附加到首选项层次结构时调用。 确保调用超级实现。
| 参数(Parameters) | |
|---|---|
preferenceManager |
PreferenceManager: The PreferenceManager of the hierarchy. |
void onBindView (View view)
将创建的视图绑定到此首选项的数据。
这是抓取对布局和自定义属性的自定义视图的引用的好地方。
确保调用超类的实现。
| 参数(Parameters) | |
|---|---|
view |
View: The View that shows this Preference. |
也可以看看:
void onClick ()
处理点击偏好。 这包括将值保存到SharedPreferences 。 但是,重写的方法应该调用callChangeListener(Object)以确保客户端想要用新值更新首选项的状态。
View onCreateView (ViewGroup parent)
创建要在PreferenceActivity显示的此视图的视图。 默认行为是夸大这种偏好(见主要布局setLayoutResource(int) 。如果改变这种行为,请指定ViewGroup ID为widget_frame 。
确保调用超类的实现。
| 参数(Parameters) | |
|---|---|
parent |
ViewGroup: The parent that this View will eventually be attached to. |
| 返回(Returns) | |
|---|---|
View |
The View that displays this Preference. |
也可以看看:
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 onPrepareForRemoval ()
当此首选项从层次结构中删除时调用。 您应该删除对此知识的任何引用。 确保通过超类实现进行调用。
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 onSetInitialValue (boolean restorePersistedValue,
Object defaultValue)
执行此操作来设置首选项的初始值。
如果restorePersistedValue为true,则应从SharedPreferences恢复首选项值。 如果restorePersistedValue为false,则应将Preference值设置为给定的defaultValue(并且如果shouldPersist()为true,则可能存储为SharedPreferences)。
这可能并不总是被称为。 一个例子是,如果它不应该坚持,但没有给出默认值。
| 参数(Parameters) | |
|---|---|
restorePersistedValue |
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. |
boolean persistBoolean (boolean value)
尝试将布尔值保存到 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
value |
boolean: The value to persist. |
| 返回(Returns) | |
|---|---|
boolean |
True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) |
boolean persistFloat (float value)
尝试持续浮动到 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
value |
float: The value to persist. |
| 返回(Returns) | |
|---|---|
boolean |
True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) |
boolean persistInt (int value)
尝试持续int到 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
value |
int: The value to persist. |
| 返回(Returns) | |
|---|---|
boolean |
True if the Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) |
boolean persistLong (long value)
尝试持续很长时间到 SharedPreferences 。
| 参数(Parameters) | |
|---|---|
value |
long: The value to persist. |
| 返回(Returns) | |
|---|---|
boolean |
True if this Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) |
boolean persistString (String value)
尝试将字符串保存到 SharedPreferences 。
这将检查此首选项是否持久,从 PreferenceManager获取编辑器,放入字符串中,并检查是否应提交(如果提交则提交)。
| 参数(Parameters) | |
|---|---|
value |
String: The value to persist. |
| 返回(Returns) | |
|---|---|
boolean |
True if the Preference is persistent. (This is not whether the value was persisted, since we may not necessarily commit if there will be a batch commit later.) |
也可以看看:
boolean shouldPersist ()
检查在给定时间调用此方法时,此首选项是否应将其值存储/恢复到SharedPreferences 。 这至少会检查此首选项是否持久,并且它目前有一个密钥。 在从SharedPreferences保存/恢复之前,请先检查这一点。
| 返回(Returns) | |
|---|---|
boolean |
True if it should persist the value. |