Skip to content

Instantly share code, notes, and snippets.

@kassadin
Last active August 29, 2015 14:06
Show Gist options
  • Save kassadin/ad115fdad8f6e934e803 to your computer and use it in GitHub Desktop.
Save kassadin/ad115fdad8f6e934e803 to your computer and use it in GitHub Desktop.
android 退出时弹出对话框
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("程序名称")
.setCancelable(true)
.setMessage("确定退出?")
.setPositiveButton("是的", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// System.exit(0);
getParent().finish();
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
return super.onKeyDown(keyCode, event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment