前言

  这段时间在研究android平台上的开源项目——StandupTimer,这是由jwood所设计的一个较为简单android应用,用于控制会议时间,类似秒表倒计时。

PreferenceActivity

  PreferenceActivity是android提供的对系统信息和配置进行自动保存的Activity,它通过[SharedPreference](http://developer.android.com/reference/android/content/SharedPreferences.html)方式将信息保存在XML 文件当中。使用PreferenceActivity不需要我们对SharedPreference进行操作,系统会自动对Activity 的各种View上的改变进行保存(这个真是太赞了!)。
  在android项目中添加一个 android xml 文件需要注意的是这次选择的是 Preference。而不是以往的Layout
![](http://pic002.cnblogs.com/img/xinsuhui/201009/2010090109571786.gif)
这个文件是保存在 res /xml 路径下的。

PreferenceScreen xml

  preference下的View是有限的,只有下面几个:
- CheckBoxPreference:CheckBox选择项,对应的值的ture或flase

- EditTextPreference:输入编辑框,值为String类型,会弹出对话框供输入。

- ListPreference: 列表选择,弹出对话框供选择。

- Preference:只进行文本显示,需要与其他进行组合使用。

- PreferenceCategory:用于分组。

- RingtonePreference:系统玲声选择
更多关于 PreferenceScreen的介绍可以查看博客园上的一篇文章:[Android之PreferenceActivity](http://www.cnblogs.com/wservices/archive/2010/07/08/1773449.html)
<div>
  <span style="color: #0000ff;"><?</span><span style="color: #ff00ff;">xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;</span><span style="color: #0000ff;">?></span>

«/span>PreferenceScreen xmlns:android=”http://schemas.android.com/apk/res/android”> «/span>CheckBoxPreference android:key=”sounds” android:title=”@string/play_sounds” android:summary=”@string/play_sounds_summary” android:defaultValue=”true”></CheckBoxPreference> «/span>EditTextPreference android:key=”warning_time” android:title=”@string/warning_time” android:summary=”@string/warning_time_summary” android:defaultValue=”15″ android:inputType=”phone” android:digits=”0123456789″></EditTextPreference> «/span>CheckBoxPreference android:key=”unlimited_participants” android:title=”@string/unlimited_participants” android:summary=”@string/unlimited_participants_summary” android:defaultValue=”false”></CheckBoxPreference> «/span>CheckBoxPreference android:key=”variable_meeting_length” android:title=”@string/variable_meeting_length” android:summary=”@string/variable_meeting_length_summary” android:defaultValue=”false”></CheckBoxPreference> </PreferenceScreen>

<div class="cnblogs_code_toolbar">
  <span class="cnblogs_code_copy"><a style="color: green;" title="复制代码">![复制代码](http://common.cnblogs.com/images/copycode.gif)</a></span>
</div>
&nbsp;





android:key 唯一标识符。它对应保存的XML保存的配置文件中的节点的 name属性