-1

如何添加切换按钮以使应用程序中的所有声音静音/取消静音,最好是有关如何操作的视频。

4

1 回答 1

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);
            }
        });
        // ...
    }
    // ...
}

Create a method called setAudio() that takes a boolean value and sets the audio :)

private void setAudio(boolean audioToggle) {
    // your code to toggle the audio
}
于 2013-03-24T03:45:54.257 回答