好的,所以我在对话框中有一个自定义视图,但它的 onKeyDown 永远不会被调用。我也尝试过 onKeyPreIme 但没有用,并且将对话框的 setCancelable 设置为 true 也无济于事。
编辑 :
//Removed all unnecessary code
public class CustomView extends LinearLayout
{
@Override
public boolean onKeyDown (int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
//do stuff here
return true;
}
return super.onKeyDown(keyCode, event);
}
}
public class CustomDialog
{
Dialog dialog;
public class CustomDialog(Context context)
{
dialog = new Dialog(context);
dialog.setContentView(R.layout.test);// the test.xml has CustomView
}
}