Last active
August 29, 2015 14:06
-
-
Save kassadin/ad115fdad8f6e934e803 to your computer and use it in GitHub Desktop.
android 退出时弹出对话框
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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