How do you set min and max dates in an Android DatePicker?

前端 未结 3 1344
渐次进展
渐次进展 2021-01-17 23:11

I am using Android\'s default date picker and my min supported SDK is 10 and I want to set the min and the max dates of the date picker.

Here is what I have in my M

3条回答
  •  走了就别回头了
    2021-01-17 23:56

    You can get the underlying DatePicker from a DatePickerDialog (by simply calling getDatePicker()) and set its bounds using:

    • setMinDate(long minDate)
    • setMaxDate(long maxDate)

    Where the argument is the usual number of milliseconds since January 1, 1970 00:00:00 in the default time zone. You'll still have to calculate these values of course, but that should be trivial to do with the Calendar class: just pass current date and add or substract x years from that..

提交回复
热议问题