android studio 在 datepicker kotlin 中防止过去的日期

android studio prevent past date in datepicker kotlin

如何从日期选择器中禁用过去的日期而不禁用未来的日期?我知道它在 startCalendar.set 附近,但我找不到 setMinValue。

/* Calendar Start Date Button Click */
        startdatepicker = findViewById(R.id.CalendarStartImage)
        startdateview = findViewById(R.id.StartDateTextView)
        val startCalendar = Calendar.getInstance()

        val startPicker = DatePickerDialog.OnDateSetListener{ view, year, month,dayOfMonth ->
            startCalendar.set(Calendar.YEAR,year)
            startCalendar.set(Calendar.MONTH,month)
            startCalendar.set(Calendar.DAY_OF_MONTH,dayOfMonth)
            

            updateStartCalendar(startCalendar)
        }
        startdatepicker.setOnClickListener{
            DatePickerDialog(this,startPicker,startCalendar.get(Calendar.YEAR),startCalendar.get(Calendar.MONTH),
                startCalendar.get(Calendar.DAY_OF_MONTH)).show()
        }

尝试用这样的东西替换 setOnClickListener 的内容

val dialog = DatePickerDialog(this,startPicker, startCalendar.get(Calendar.YEAR), startCalendar.get(Calendar.MONTH), startCalendar.get(Calendar.DAY_OF_MONTH))
dialog.datePicker.minDate = startCalendar.getTimeInMillis()
dialog.show()