I am trying to make a calendar date picker dialog pop-up with a condition. User selects month and year at first. Hence, DatePickerDialog pop-up will show with minimum 28 days (for February only) and maximum 31days (for January, March, May, …, December). User is able to pick particular date in a previously selected month of the year.
Thus, those dates on which user gave attendance are set enabled, rest dates are set disabled.
Now, there may be a situation that user was absent for the whole month. I want to show all the dates set disabled in the calendar for that particular month of the year. I was looking at the documentation that there were methods called setSelectableDays(Calendar[] days) and setDisabledDays(Calendar[] days), both takes @NonNull array of calendar objects to enable and disable dates repectively.
So, for this case if there was no attendance date for a particular month, I tried to make a absentDates array of calendar and passed it to the second method i.e. setDisabledDays(Calendar[] days). But, it not showing anything. I tried and checked that except one day in a specific month, I can disable rest days, not all the dates at once (an image is attached of that). I want all the dates disabled in the DatePickerDialog pop-up.
How to show Material Calendar with all disabled dates in Android datePickerDialog
724 Views Asked by Sumit Bikram Maity At
1

If you use the official
MaterialDatePickeryou can implement your ownDateValidatorto enable/disable days and setting it to theCalendarConstraintsobject before building the dialog withMaterialDatePicker.Builder().datePicker().setCalendarConstraints(contraints)You can find a sample implementation here for DateValidatorPointForward.
Documentation: https://material.io/components/date-pickers/android#using-date-pickers