我已经为日期范围选择实现了这一点。
如何限制日期范围的限制。我希望用户从所选的开始日期最多选择 7 天。
在下面添加我的代码,
private fun showDateRangePicker() {
val constraintsBuilder = CalendarConstraints.Builder()
val validators: ArrayList<CalendarConstraints.DateValidator> = ArrayList()
validators.add(DateValidatorPointBackward.before(MaterialDatePicker.todayInUtcMilliseconds()))
validators.add(DateValidatorWeekdays())
constraintsBuilder.setValidator(CompositeDateValidator.allOf(validators))
val dateRangePicker =
MaterialDatePicker.Builder.dateRangePicker()
.setTitleText("Select dates")
.setTheme(R.style.MaterialCalendarTheme)
.setSelection(Pair(MaterialDatePicker.todayInUtcMilliseconds(), MaterialDatePicker.todayInUtcMilliseconds()))
.setCalendarConstraints(constraintsBuilder.build())
.build()
dateRangePicker.show(supportFragmentManager, dateRangePicker.toString())
}