在对话框中按下音量调高时隐藏 UI [英] Hide UI when volume up down pressed in a dialog
本文介绍了在对话框中按下音量调高时隐藏 UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在按下 volume_up/volume_down 键时隐藏音量 ui.我知道它可以通过一个活动来完成,当它在显示对话框时被触发时似乎不起作用.
Is there a way to hide the volume ui when the volume_up/volume_down key is pressed. I understand that it can be done with an activity when it doesnt seem to work when tiggered when a dialog is shown.
有解决办法吗?
推荐答案
这应该适用于 Dialog 类:
This should work with the Dialog class:
AudioManager man = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
dialog.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_VOLUME_UP:
man.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE,
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
man.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER,
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
return true;
default:
return super.onKeyDown(keyCode, event);
}
}
});
这篇关于在对话框中按下音量调高时隐藏 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文