Preference 类 用来定义首选项,并向用户显示设置界面。
使用Preference可以自动帮助我们对配置页的自动存储功能。配置文件存放位置:/data/data/应用包名/shared_prefs/xxx.xml
示例:
首先编写我们的配置布局文件xxx.xml,文件放在工程目录res/xml/下,如:res/xml/xxx.xml。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="我的位置源" >
<CheckBoxPreference
android:key="wireless_network"
android:summary="使用无线网络查看应用程序(例如Google地图)中的位置"
android:title="使用无线网络" />
<CheckBoxPreference
android:key="gps_satellite_setting"
android:summary="定位时,精确到街道级别(取消选择可节约电量)"
android:title="启用GPS卫星设置" />
</PreferenceCategory>
<PreferenceCategory android:title="个人信息设置" >
<CheckBoxPreference
android:key="yesno_save_individual_info"
android:title="是否保存个人信息" />
<EditTextPreference
android:dialogIcon="@drawable/ic_launcher"
android:dialogTitle="设置姓名"
android:key="individual_name"
android:summary="请输入真实姓名"
android:title="姓名" />
<PreferenceScreen
android:key="other_individual_msg"
android:summary="是否工作、手机"
android:title="其他个人信息" >
<CheckBoxPreference
android:key="is_an_employee"
android:title="是否工作" />
<EditTextPreference