【发布时间】:2015-12-24 02:54:30
【问题描述】:
我想在 android 中禁用日期选择器的过去日期。 我可以通过使用来做到这一点
dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
这工作正常,日期选择器中的过去日期看起来已禁用。但我仍然可以单击前一个日期并选择它。 如何不让这种情况发生? 下面是我的日期选择器的屏幕截图:-
这是我禁用过去日期的代码:-
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
mActivity = new WeakReference<CreateEvent>(
(CreateEvent) getActivity());
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
if(callingView==fromDate){
dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
}else if (callingView==toDate){
dialog.getDatePicker().setMinDate(fromD);
}
// Create a new instance of DatePickerDialog and return it
return dialog;
}
【问题讨论】:
-
是lolipop的bug,低版本可以查看。对于解决方案,您需要将您的逻辑应用于
onDateSet方法的回调。
标签: android date datepicker android-datepicker