<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="设置选项1" >
<CheckBoxPreference
android:defaultValue="是否开启checkbox"
android:enabled="true"
android:key="checkboxkey"
android:summary="摘要"
android:summaryOff="我被关闭啦 嘎嘎"
android:summaryOn="我被开启啦 哈哈"
android:title="标题" />
</PreferenceCategory>
<PreferenceCategory android:title="设置选项2" >
<ListPreference
android:dialogTitle="请选择"
android:entries="@array/arraykey"
android:entryValues="@array/arrayvalues"
android:key="listselcet"
android:negativeButtonText="取消"
android:summary="请在对话框里面选择"
android:title="选择条目" />
</PreferenceCategory>
</PreferenceScreen>
package cn.itcast.preferenceactivity;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class PreferenceActivityActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
System.out.println(getPreferenceManager().getSharedPreferences().getBoolean("checkboxkey", false));
}
}