阅读更多
/**监听对话框里面的button点击事件*/      DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener()      {          public void onClick(DialogInterface dialog, int which)          {              switch (which)              {              case AlertDialog.BUTTON_POSITIVE:// "确认"按钮退出程序              finish();                //这里处理退出前跳到首个加载界面后执行下面的退出Intent intent = new Intent();intent.setClass(MainActivity.this, MainActivity.class);startActivity(intent);// 退出程序Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);mHomeIntent.addCategory(Intent.CATEGORY_HOME);mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);startActivity(mHomeIntent);// 第二次关闭android.os.Process.killProcess(android.os.Process.myPid());                break;              case AlertDialog.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框                  break;              default:                  break;              }          }      };        @Override      public boolean onKeyDown(int keyCode, KeyEvent event)      {          if (keyCode == KeyEvent.KEYCODE_BACK )          {              // 创建退出对话框              AlertDialog isExit = new AlertDialog.Builder(this).create();              // 设置对话框标题              isExit.setTitle("系统提示");              // 设置对话框消息              isExit.setMessage("确定要退出吗");              // 添加选择按钮并注册监听              isExit.setButton("确定", listener);              isExit.setButton2("取消", listener);              // 显示对话框              isExit.show();          }          return false;                }

更多相关文章

  1. 自定义对话框Dialog
  2. 窗体两个按钮各占一半
  3. RadioGroup和RadioButton
  4. 自定义单选按钮(RadioButton)的样式
  5. ToggleButton例子
  6. android-RelativeLayout实现顶部、中部、底部布局
  7. Android(安卓)UI控件学习笔记(二)
  8. Android按钮控件之RadioGroup和RadioButton
  9. Android的AlertDialog详解

随机推荐

  1. Android(安卓)代码规范 code style
  2. android 2.2(froyo)源码下载
  3. android 学习笔记(一):2 模拟器的使用
  4. [Linphone Android] 登录实现
  5. android软银盘始终显示,并显示在焦点上
  6. Android:再按一次退出程序
  7. Android开发经验分享
  8. Android(安卓)超仿Path时间轴和扇形菜单
  9. 【攻克Android(安卓)(1)】安装Android(安
  10. android 权限permission 说明