Search code examples
androidmediavolume

Custom theme for Media Volume Controller (whatever it's called) of Android?


I'm trying custom the theme of Media Volume Controller (I don't know what it's called, just try to name it). It's something like a Toast with "Media Volume" title which appears when we press volume buttons (+ and -) in games. But I don't know which View it's, or it's a Toast, a Dialog. So far as I try, I could not find anything which refers it. Only Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC) to enable it in your Activity, and nothing more. If someone know how to custom it, or just it's name, please help me! Thanks.


Solution

  • Sorry for my misunderstanding of your question.

    I think the way you can customize "Media Volume Controller" is control volume yourself and show your customize view(or Toast). Because the "Media Volume" Toast(It is a Toast, see the source code of VolumePanel.onShowVolumeChanged ) is created and shown by android system which you cannot customize.

    Here is the sample code which 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);
    }