如何在应用声音中添加将所有声音静音/取消静音的切换按钮,最好是关于如何操作的视频。
答案 0 :(得分:0)
public class MyActivity extends Activity {
private boolean _myAudioToggle;
onCreate(Bundle savedInstanceState) {
// ...
_myAudioToggle = false; // audio is off, set to true to default to on
setAudio(_myAudioToggle);
Button button = (Button) findViewById(R.id.yourButton); // where yourButton is in your layout XML file
button.setOnClickListener(new View.onClickListener {
@Override
onClick(View v) {
_myAudioToggle = !_myAudioToggle;
setAudio(_myAudioToggle);
}
});
// ...
}
// ...
}
创建一个名为setAudio()的方法,它接受一个布尔值并设置音频:)
private void setAudio(boolean audioToggle) {
// your code to toggle the audio
}