xml
android:key="checkbox_preference" android:title="Checkbox Preference" android:summary="This is a checkbox preference" android:defaultValue="false" /> android:key="list_preference" android:title="List Preference" android:summary="This is a list preference" android:entries="@array/list_entries" android:entryValues="@array/list_entry_values" android:defaultValue="0" />
java public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); } }
java SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean isChecked = sharedPreferences.getBoolean("checkbox_preference", false); // 修改Preferences SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("checkbox_preference", true); editor.apply();