- public void onBackPressed() {
- onBackPressed_local(this);
- }
- public void onBackPressed_local(final Activity context) {
- Dialog dialog = new AlertDialog.Builder(context)
- .setTitle("您确定要退出系统吗?") //设置标题
- .setMessage("系统提示") // 设置内容
- .setPositiveButton("确定", // 设置确定按钮
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- finish();
- }
- })
- .setNeutralButton("取消", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) { // 点击"退出"按钮之后推出程序
- return;
- }
- }).create(); // 创建按钮
- dialog.show(); // 显示对话框
- }
- //该片段来自于http://www.codesnippet.cn/detail/260620134309.html
来源: http://www.codesnippet.cn/detail/260620134309.html