如何在 DatePickerDialog Android 中禁用今天日期之后的日期?

How to disable dates after today date in DatePickerDialog Android?

我想在 DatePickerDialog 中禁用从 今天 开始的所有 Next(after) 日期。

我正在使用以下代码创建 DatePickerDialog:

    Calendar calendar = Calendar.getInstance();
    mYear = calendar.get(Calendar.YEAR);
    mMonth = calendar.get(Calendar.MONTH);
    mDay = calendar.get(Calendar.DAY_OF_MONTH);

 //OnDateSetListener
 private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker arg0, int year, int monthOfYear, int dayOfMonth) {
        calendar.set(year, monthOfYear, dayOfMonth);
        String currentDate = date_format.format(calendar.getTime());
        ...
    }
};
 //Create DatePickerDialog here
 protected Dialog onCreateDialog(int id) {
    if (id == 999) {
        DatePickerDialog dpDialog = new DatePickerDialog(getContext(), myDateListener, mYear, mMonth, mDay);

        return dpDialog;
    }
    return null;
}

请建议我如何禁用日期选择器对话框中的所有先前日期。

只需在 DatePickerDialogsetMaxDate() 中传递当前日期。

DatePickerDialog dpDialog = new DatePickerDialog(getContext(), myDateListener, mYear, mMonth, mDay);
dpDialog.getDatePicker().setMaxDate(calendar.getTimeInMillis());

dpDialog.getDatePicker().setMaxDate(System.currentTimeMillis());