如何在MaterialDatePicker中禁用过去的日期? [英] How to disable past dates in MaterialDatePicker?
本文介绍了如何在MaterialDatePicker中禁用过去的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//Material Date Picker
private val calendar = Calendar.getInstance()
private val constraintsBuilder = CalendarConstraints.Builder().setStart(calendar.timeInMillis)
private val builder = MaterialDatePicker.Builder.datePicker()
private val picker = builder
.setSelection(calendar.timeInMillis)
.setInputMode(MaterialDatePicker.INPUT_MODE_CALENDAR)
.setCalendarConstraints(constraintsBuilder.build())
.build()
我在上面使用代码以打开日历setSelection方法选择当前日期,而setStart仅适用于当前月份,因此我无法选择上个月的日期,但我仍然可以选择当前月份的过去日期。
I am using above code to open calendar setSelection method select current date and setStart only works for current month So i am unable to select previous month dates but i can still select past dates of current month.
如果有什么可以帮助我的。请告诉我。谢谢。
If any can help me out. Please let me know. Thanks.
推荐答案
您可以构建自己的 DateValidator
,也可以使用库提供的 DateValidatorPointForward
。
You can build your own DateValidator
or you can just use the DateValidatorPointForward
provided by the library.
类似的东西:
//Returns a DateValidator which enables days from {@code point}, in
//UTC milliseconds, forward
CalendarConstraints.DateValidator dateValidator = DateValidatorPointForward.from(yourDate);
constraintsBuilder.setValidator(dateValidator);
这篇关于如何在MaterialDatePicker中禁用过去的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文