有没有办法在运行对话框时禁用“按键音量增大/减小”?? !!
AlertDialog.Builder builder1 = new AlertDialog.Builder(thisActivity);
builder1.setMessage("Flight mode is ON");
builder1.setCancelable(true);
builder1.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Intent intent = new Intent(context,MainActivity.class);
startActivity(intent);
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
出现对话框时--->用户无法使用键音量上/下
答案 0 :(得分:1)
覆盖活动中的onKeyDown函数。如果对话框已启动且您收到音量键事件,请忽略它(在这些情况下不要调用super.onKeyDown)。
答案 1 :(得分:1)
捕获关键事件但不做任何事情:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
//do nothing
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//do nothing
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}