/**监听对话框里面的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. Android(安卓)获取天气预报
  2. android:padding和android:margin的区别
  3. Android之Button按钮
  4. 系出名门 Android(安卓)系列文章索引
  5. Android中的动画详解系列【4】——Activity之间切换动画
  6. Android(安卓)Studio对话框登录。。。
  7. Android(安卓)两个可拖动的SeekBar 两点拖动
  8. Android(安卓)全退出
  9. 自定义对话框Dialog

随机推荐

  1. Sending email without user interaction
  2. Android(安卓)中文 API (35) —— ImageSwi
  3. Android(安卓)EditText不弹出软键盘
  4. android开发 列表显示(ListView)
  5. android 电容屏(二):驱动调试之基本概念篇
  6. Android(安卓)后台任务(五)Service
  7. ImageView的scaletype属性
  8. 链接器解析多重定义的全局变量
  9. android 来电自动接听和自动挂断
  10. Do's and Don'ts for Android(安卓)devel