Android 在运行对话框时禁用“增大/减小音量”键

Android 在运行对话框时禁用“增大/减小音量”键,android,Android,有没有办法在运行对话框时禁用“键音量增大/减小” AlertDialog.Builder builder1 = new AlertDialog.Builder(thisActivity); builder1.setMessage("Flight mode is ON"); builder1.setCancelable(true); builder1.setPositiveButton("OK", new DialogInterface.OnClickListener() { public voi

有没有办法在运行对话框时禁用“键音量增大/减小”

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();

当对话框出现时--->用户不能在“活动”中使用“音量向上/向下”键

覆盖onKeyDown功能。如果对话框处于打开状态,并且您收到卷键事件,请忽略它(在这些情况下不要调用super.onKeyDown)。

覆盖活动中的onKeyDown函数。如果对话框处于打开状态,并且您收到卷键事件,请忽略它(在这些情况下不要调用super.onKeyDown)。

覆盖活动中的onKeyDown函数。如果对话框处于打开状态,并且您收到卷键事件,请忽略它(在这些情况下不要调用super.onKeyDown)。

覆盖活动中的onKeyDown函数。如果对话框打开,并且您收到一个卷密钥事件,请忽略它(在这些情况下不要调用super.onKeyDown)。

捕获密钥事件,但不要执行任何操作:

@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);
        }
    }

捕获关键事件,但不要做任何事情:

@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);
        }
    }

捕获关键事件,但不要做任何事情:

@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);
        }
    }

捕获关键事件,但不要做任何事情:

@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);
        }
    }