问题描述
- DatePickerDialog中为什么点击屏幕外不消失?
-
final Calendar objTime = Calendar.getInstance();
int iYear = objTime.get(Calendar.YEAR);
int iMonth = objTime.get(Calendar.MONTH);
int iDay = objTime.get(Calendar.DAY_OF_MONTH);DatePickerDialog datePickerDialog = new DatePickerDialog(QueryDateActivity.this, DatePickerListener, iYear, iMonth, iDay); datePickerDialog.setCanceledOnTouchOutside(true); datePickerDialog.show(); 我已经设置为true了 可是还是不消失为什么? /**下面是原代码 */ final DatePickerDialog mDialog_start = new DatePickerDialog(this, null, con_year_start, con_month_start, con_day_start); //手动设置按钮 mDialog_start.setButton(DialogInterface.BUTTON_POSITIVE, "完成", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //通过mDialog.getDatePicker()获得dialog上的DatePicker组件,然后可以获取日期信息 DatePicker datePicker = mDialog_start.getDatePicker(); int year = datePicker.getYear(); int month = datePicker.getMonth(); int day = datePicker.getDayOfMonth(); tv_start.setText(year+"/"+months[month]+"/"+day); con_year_start = year; con_month_start = month; con_day_start = day; } }); //取消按钮,如果不需要直接不设置即可 mDialog_start.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mDialog_start.dismiss(); } }); mDialog_start.setTitle("请选择开始时间"); mDialog_start.setCanceledOnTouchOutside(true); mDialog_start.show();
解决方案
你不是设置了取消吗 干嘛要有强迫症 再说 用户也会按回退
解决方案二:
把setCancelable()也设置一下,另外看一下是不是重写了ondispatchevent()或者onTouchEvent之类的方法。
时间: 2024-10-30 09:58:31