Android Can';t在DatePickerDialog上设置当前日期
这是我的代码:Android Can';t在DatePickerDialog上设置当前日期,android,datepicker,Android,Datepicker,这是我的代码: DatePickerDialog dialog = new DatePickerDialog(OtherEventActivity.this, R.style.DatePickerDialogTheme, new DateSetListener(), mYear, (mMonth), mDay); try { dialog.getDatePicker().setMaxDate(System.currentTimeMillis()); } catch (Exce
DatePickerDialog dialog = new DatePickerDialog(OtherEventActivity.this, R.style.DatePickerDialogTheme,
new DateSetListener(), mYear, (mMonth), mDay);
try {
dialog.getDatePicker().setMaxDate(System.currentTimeMillis());
} catch (Exception e) {}
dialog.show();
当我启动应用程序时,我无法在安卓5上按当前日期(更高或更低版本都可以)
UPD-我也试过:
dialog.getDatePicker().setMaxDate(new Date().getTime());
安卓5中有一个bug。如果将“最大日期”设置为“今天”,则日期选择器不允许您选择当前日期。我使用的变通方法是
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
dialog.getDatePicker().setMaxDate(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(24));
else
dialog.getDatePicker().setMaxDate(System.currentTimeMillis());
这不是一个完美的解决方案,但它很有效。安卓5中有一个bug。如果将“最大日期”设置为“今天”,则日期选择器不允许您选择当前日期。我使用的变通方法是
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
dialog.getDatePicker().setMaxDate(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(24));
else
dialog.getDatePicker().setMaxDate(System.currentTimeMillis());
这不是一个完美的解决方案,但它是有效的