How to set minimum DatePicker date to current date

前端 未结 9 1672
有刺的猬
有刺的猬 2020-11-28 07:30

I want to set the minimum date the user can choose in a DatePicker to the current date. I\'ve tried this:

DatePicker datePicker = (DatePicker) findViewById(R         


        
相关标签:
9条回答
  • 2020-11-28 08:05

    Adding this line to your DatePicker Fragment will set the minimum date as current date & disable the previous months.

    datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis());
    
    0 讨论(0)
  • 2020-11-28 08:08

    If you don't want to use a custom dialog. Use this single line code:

    datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()); 
    
    0 讨论(0)
  • 2020-11-28 08:10
    datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()); 
    

    OR

    DatePickerDialog dialog = new DatePickerDialog(this, this,
              Calendar.YEAR,Calendar.MONTH,
                Calendar.DAY_OF_MONTH);
    
        dialog.getDatePicker().setMinDate(Calendar.getInstance().getTimeInMillis());
        dialog.show();
    
    0 讨论(0)
提交回复
热议问题