如何从android中的主要活动中引用选项菜单中的复选框?
我可以在菜单选项中选择“静音”,如下所示:如何从android中的主要活动中引用选项菜单中的复选框?,android,menu,checkbox,Android,Menu,Checkbox,我可以在菜单选项中选择“静音”,如下所示: <?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="
<?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>
现在如何检查该复选框是否已选中?在
活动中使用以下内容:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean muteSound = prefs.getBoolean("muteSound", false);
您必须获得以下信息:
然后读取值:
preferences.getBoolean("muteSound", true) //the second argument is the default value
preferences.getBoolean("muteSound", true) //the second argument is the default value