Android 获取活动中CheckBoxPreference的值
我有一个preferences.xml:Android 获取活动中CheckBoxPreference的值,android,checkbox,android-activity,preferences,Android,Checkbox,Android Activity,Preferences,我有一个preferences.xml: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="Category"> <CheckBoxPrefere
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Category">
<CheckBoxPreference
android:key = "inputPreferences"
android:title = "Title"
android:summary = "Subtitle"/>
</PreferenceCategory>
</PreferenceScreen>
希望任何人都能提供帮助,谢谢:)您需要使用在xml文件中设置的密钥属性。将android:key更改为“checkbox”而不是“inputPreferences”您需要使用在xml文件中设置的key属性。将安卓:键改为“复选框”而不是“输入首选项”
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_LONG).show();
SharedPreferences myPreference=PreferenceManager.getDefaultSharedPreferences(this);
if(myPreference.getBoolean("checkbox", false)) {
VarText.setVisibility(View.VISIBLE);
VarText.setText("foo");
}
}