android 返回 弹出对话框 确认退出

[java] view plain copy
  1. privatevoiddialog(){
  2. AlertDialog.Builderbuilder=newBuilder(PPTSoftwareActivity.this);
  3. builder.setMessage("确认要退出么?");
  4. builder.setTitle("提示");
  5. builder.setPositiveButton("确定",newDialogInterface.OnClickListener(){
  6. publicvoidonClick(DialogInterfacedialog,intwhich){
  7. //TODOAuto-generatedmethodstub
  8. dialog.dismiss();
  9. finish();
  10. }
  11. });
  12. builder.setNegativeButton("取消",newDialogInterface.OnClickListener(){
  13. publicvoidonClick(DialogInterfacedialog,intwhich){
  14. //TODOAuto-generatedmethodstub
  15. dialog.dismiss();
  16. }
  17. });
  18. builder.show();
  19. }

[java] view plain copy
  1. @Override
  2. publicbooleanonKeyDown(intkeyCode,KeyEventevent){
  3. //TODOAuto-generatedmethodstub
  4. if(keyCode==KeyEvent.KEYCODE_BACK){
  5. dialog();
  6. }
  7. returnfalse;
  8. }

你可能感兴趣的:(android)