在界面有对话框的情况下长按返回键只会取消对话框,并不会一直返回。
现项目要求长按返回键需要一直返回。
dialog.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(DialogInterface dialog1, int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && dialog.isShowing() && event.getAction() == MotionEvent.ACTION_DOWN) {
dialog.dismiss();
return true;
}
return false;
}
});
dialog.setOnDismissListener(new OnDismissListener()
{
public void onDismiss(DialogInterface dialog)
{
System.out.println(" ````````` ");
}
});
返回值含义:
Activity public boolean onKeyDown(int keyCode, KeyEvent event)
* @return Return <code>true</code> to prevent this event from being propagated
* further, or <code>false</code> to indicate that you have not handled
* this event and it should continue to be propagated.
DialogInterface interface OnKeyListener {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event);
}