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 he开发者_如何学JAVAlp me! Thanks.
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);
}
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);
}
精彩评论