Custom theme for media volume controller (as it is called) Android?

I am trying to customize the theme of the media volume controller (I don’t know what it is called, just try to name it). This is something like a toast with the heading “Media Volume” that appears when we press the volume buttons (+ and -) in games. But I do not know what kind of view it is, or whether it is a toast, a dialogue. As far as I try, I could not find anything that would call it. Only Activity.setVolumeControlStream (AudioManager.STREAM_MUSIC) to include it in your activity, and nothing more> _ <If someone knows how to configure it, or just its name, please help me! Thank.

+3
source share
2 answers

Sorry for my misunderstanding of your question.

I think that you can configure the "Media Volume Controller" yourself and control your volume (or Toast). Because the "Media Volume Toast" (this is a toast, see the Source Code of VolumePanel.onShowVolumeChanged ) is created and displayed by the Android system, which you cannot configure.

Here is sample code that might solve your problem:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        // Or use adjustStreamVolume method.
        am.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
        Toast.makeText(this, "Volume up", Toast.LENGTH_SHORT).show();
        return false;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        // Or use adjustStreamVolume method.
        am.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);
        Toast.makeText(this, "Volume down", Toast.LENGTH_SHORT).show();
        return false;
    }
    return super.onKeyDown(keyCode, event);
}
+7
source

You can override onKeyDownyour gaming activity. And show "Toast" according to the pressed key. onKeyDownwill be called when you press a key in your activity. The following is sample code:

public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        // show volumn up toast
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        // show volumn down toast
    }
    return super.onKeyDown(keyCode, event);
}
0
source

Source: https://habr.com/ru/post/1768594/


All Articles