主要活动
@Override public void onCreate() {
super.onCreate();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
boolean checked = settings.getBoolean("test", false);
}
首选项.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings">
<CheckBoxPreference android:key="test" android:title="test" android:defaultValue="false"/>
</PreferenceScreen>
环境
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Setting extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
尽管我勾选了复选框,但检查的结果总是错误的