1.背景音乐在menu中设置:
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.echo.sb.MainActivity" >
<item
android:id="@+id/action_settings"
android:title="设置音乐开关"/>
</menu>
2.使用到sharedPreference:在res中的xml目录下
preference.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="music"
android:title="播放背景音乐"
android:summary="play or stop"
android:defaultValue="true"
/>
</PreferenceScreen>