跳转到相应内容

最常访问

最近访问

navigation
added in API level 1

android.preference

Provides classes that manage application preferences and implement the preferences UI. Using these ensures that all the preferences within each application are maintained in the same manner and the user experience is consistent with that of the system and other applications.

The preferences portion of an application should be ran as a separate Activity that extends the PreferenceActivity class. In the PreferenceActivity, a PreferenceScreen object should be the root element of the layout. The PreferenceScreen contains Preference elements such as a CheckBoxPreference, EditTextPreference, ListPreference, PreferenceCategory, or RingtonePreference.

All settings made for a given Preference will be automatically saved to the application's instance of SharedPreferences. Access to the SharedPreferences is simple with getSharedPreferences().

Note that saved preferences are accessible only to the application that created them.

Interfaces

Preference.OnPreferenceChangeListener Interface definition for a callback to be invoked when the value of this Preference has been changed by the user and is about to be set and/or persisted. 
Preference.OnPreferenceClickListener Interface definition for a callback to be invoked when a Preference is clicked. 
PreferenceDataStore A data store interface to be implemented and provided to the Preferences framework. 
PreferenceFragment.OnPreferenceStartFragmentCallback This interface was deprecated in API level P. Use PreferenceFragmentCompat.OnPreferenceStartFragmentCallback  
PreferenceManager.OnActivityDestroyListener Interface definition for a class that will be called when the container's activity is destroyed. 
PreferenceManager.OnActivityResultListener Interface definition for a class that will be called when the container's activity receives an activity result. 
PreferenceManager.OnActivityStopListener Interface definition for a class that will be called when the container's activity is stopped. 

Classes

CheckBoxPreference A Preference that provides checkbox widget functionality. 
DialogPreference A base class for Preference objects that are dialog-based. 
EditTextPreference A Preference that allows for string input. 
ListPreference A Preference that displays a list of entries as a dialog. 
MultiSelectListPreference A Preference that displays a list of entries as a dialog. 
Preference Represents the basic Preference UI building block displayed by a PreferenceActivity in the form of a ListView
Preference.BaseSavedState A base class for managing the instance state of a Preference
PreferenceActivity This is the base class for an activity to show a hierarchy of preferences to the user. 
PreferenceActivity.Header Description of a single Header item that the user can select. 
PreferenceCategory Used to group Preference objects and provide a disabled title above the group. 
PreferenceFragment This class was deprecated in API level P. Use PreferenceFragmentCompat  
PreferenceGroup A container for multiple Preference objects. 
PreferenceManager Used to help create Preference hierarchies from activities or XML. 
PreferenceScreen Represents a top-level Preference that is the root of a Preference hierarchy. 
RingtonePreference A Preference that allows the user to choose a ringtone from those on the device. 
SwitchPreference A Preference that provides a two-state toggleable option. 
TwoStatePreference Common base class for preferences that have two selectable states, persist a boolean value in SharedPreferences, and may have dependent preferences that are enabled/disabled based on the current state. 
此网站会使用 Cookie 来存储您在此网站上指定的语言和显示选项偏好设置。

获取最新的 Android Developers 资讯和提示,助您在 Google Play 上取得成功。

* 必填字段

成功!

在微信上关注 Google Developers

要以浏览此网站吗?

您请求访问的是网页,但是您为此网站设置的语言偏好为

要更改您的语言偏好设置并以浏览此网站吗?如果以后您想要更改语言偏好设置,请使用每个页面底部的语言菜单。

该类需要 或更高的 API 级别

此文档已被隐藏,因为您为该文档选择的 API 级别是 。您可以使用左侧导航栏上方的选择器来更改文档的 API 级别。

要详细了解如何根据您的应用需求指定 API 级别,请参阅支持不同平台版本

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)