我可以选择在我的菜单选项中“静音”:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference android:summary="Mute all sound effects" android:title="Mute"android:key="muteSound"></CheckBoxPreference>
</PreferenceScreen>
现在如何检查是否选中了该复选框?
答案 0 :(得分:1)
在Activity
:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean muteSound = prefs.getBoolean("muteSound", false);
答案 1 :(得分:1)
你必须得到SharedPreferences:
//in the main activity you should set the default values in case user has never entered the preferences screen
PreferenceManager.setDefaultValues(this, R.xml.preferences_file, false);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
然后读取值:
preferences.getBoolean("muteSound", true) //the second argument is the default value