答案 0 :(得分:1)
您可以创建自己的DatePickerDialog类。然后在调用datePicker时以毫秒电流传递必要的日期。 <{1}}方法会停用前一天,也会停用滑动。
DatePickerDialog类:
setMinDate()
活动内部:
public class myDatePickerDialogFragment extends DialogFragment {
int mDay, mMonth, mYear;
long current;
// you also need to pass OnDateSetListener that is implemented in
// activity which is calling this datePicker
OnDateSetListener onSetDate;
public myDatePickerDialogFragment(){
}
@Override
public void setArguments(Bundle args) {
super.setArguments(args);
mDay = args.getInt("day");
mMonth = args.getInt("month");
mYear = args.getInt("year");
current = args.getLong("minDate");
}
public void setOnDateSetListener(OnDateSetListener setDate){
onSetDate = setDate;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), onSetDate, mYear, mMonth, mDay);
// here you set minimum day. User cannot chose earlier dates.
datePickerDialog.getDatePicker().setMinDate(current);
return datePickerDialog;
}
}
OnDateSetListener:
Bundle args = new Bundle();
args.putInt("day", mDay);
args.putInt("month", mMonth);
args.putInt("year", mYear);
args.putLong("minDate", yourCalendarObject.getTimeInMillis());
myDatePickerDialogFragment dialog = new myDatePickerDialogFragment();
dialog.setArguments(args);
dialog.setOnDateSetListener(datePickerListener);
dialog.show(getSupportFragmentManager(), "date");