仍然可以在日期选择器中选择禁用日期

dee*_*eep 9 android date datepicker android-datepicker

我想在android中禁用日期选择器的过去日期.我可以通过使用来做到这一点

dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
Run Code Online (Sandbox Code Playgroud)

这工作正常,日期选择器中的过去日期看起来已禁用.但我仍然可以点击之前的日期并选择它.怎么不让这种情况发生?下面是我的约会选择器的截图: -

在此输入图像描述

这是我的代码,我禁用过去的日期: -

@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;
    }
Run Code Online (Sandbox Code Playgroud)

dee*_*eep 8

从评论中得知这是Lollipop中的一个错误.所以,以编程方式修复它.

您需要做的就是检查所选日期并设置最小日期.