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.
A:
You can override the onKeyDown
of your game Activity. And show the "Toast" according to the key just pressed. onKeyDown
method will be called when a key was pressed down in your Activity. 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);
}
Tony
2010-10-08 14:46:22
Thank for your help. I also thought about it, but that Media Volume Controller is not Toast, because if it is displaying and you press volume button, it'll not re-appear but change the volume bar (a Toast'll disappear then re-appear after few seconds). And it is placed at the top of screen, not the bottom like Toast. Arghh, I wish I knew what class does it belong >_<
Anh Tuan
2010-10-09 01:57:08
A:
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);
}
Tony
2010-10-10 01:30:29