1 private void exitDialog() { 2 Dialog dialog = new AlertDialog.Builder(this).setIcon(R.drawable.pic_m) 3 .setTitle("程序退出? ").setMessage("您确定要退出本程序吗?") 4 5 .setNegativeButton("取消", new DialogInterface.OnClickListener() { 6 public void onClick(DialogInterface dialog, int which) { 7 } 8 }) 9 .setPositiveButton("确定", new DialogInterface.OnClickListener() { 10 public void onClick(DialogInterface dialog, int which) { 11 MainActivity.this.finish(); 12 } 13 }).create(); 14 15 dialog.show(); 16 } 17 18 public boolean onKeyDown(int keyCode, KeyEvent event) { 19 if (keyCode == KeyEvent.KEYCODE_BACK) { 20 this.exitDialog(); 21 } 22 return false; 23 }
时间: 2024-10-12 19:48:31