SharedPReferences的一个用途是实现设置界面,虽然现在的许大家都用它来存储基本的键值对。
/res/xml/preferences.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="General options"> <CheckBoxPreference android:key = "silent_mode" android:defaultValue="false”用 android:title="Silent Mode" android:summary="Mute all sounds from this app" /> <SwitchPreference android:key="awesome_mode" android:defaultValue="false" android:switchTextOn="Yes" android:switchTextOff="No" android:title="Awesome mode™" android:summary="Enable the Awesome Mode™ feature"/> <EditTextPreference android:key="custom_storage" android:defaultValue="/sdcard/data/" android:title="Custom storage location" android:summary="Enter the directory path where you want data to be saved. If it does not exist, it will be created." android:dialogTitle="Enter directory path (eg. /sdcard/data/ )"/> </PreferenceCategory></PreferenceScreen>以上定义了设置界面的可选项. 另外的一些可选项可以在Android官方文档查看。
另外不要忘记了在Manifest文件里面注册
是不是很简单~
普照天星【java开发工程师】20-30k http://www.jianshu.com/p/8b52751360df 产品经理20-30k http://www.jianshu.com/p/cb0ac7a00796


新闻热点
疑难解答