Disable specific dates of day in Android date picker

前端 未结 5 1525
日久生厌
日久生厌 2020-12-06 05:06

I\'m using the datePicker and I can disable last days of today and later days after 30 days by the following code:

DatePickerDialog datePicker = new DatePick         


        
5条回答
  •  执笔经年
    2020-12-06 05:58

    Try Android Material Date and Timepicker

    Source Link

    Disabled Sundays and Saturdays.

    You can also disable any specific date using setDisabledDays() method

                //Disable all SUNDAYS and SATURDAYS between Min and Max Dates
                for (Calendar loopdate = min_date_c; min_date_c.before(max_date_c); min_date_c.add(Calendar.DATE, 1), loopdate = min_date_c) {
                    int dayOfWeek = loopdate.get(Calendar.DAY_OF_WEEK);
                    if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
                        Calendar[] disabledDays =  new Calendar[1];
                        disabledDays[0] = loopdate;
                        datePickerDialog.setDisabledDays(disabledDays);
                    }
                }
    

提交回复
热议问题