8
使用setMaxDate限制DatePickerDialog上可選擇的天數後,最後一天不會變灰,但不可選。提前謝謝你的幫助。設置最大日期後DatePickerDialog的最後一天不可選擇
private void showDatePickerDialog() {
DateTime dateTime = new DateTime();
DateTime tomorrow = dateTime.plusDays(1);
int year = tomorrow.getYear();
int month = tomorrow.getMonthOfYear() -1; // zero based months
int day = tomorrow.getDayOfMonth();
DateTime thirtyDaysInFuture = dateTime.plusDays(30);
long tomorrowMilliseconds = tomorrow.getMillis();
long futureMilliseconds = thirtyDaysInFuture.getMillis();
Log.d(TAG, "YEAR: " + year + ", MONTH: " + month + ", DAY: " + day);
DatePickerDialog datePickerDialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
Log.d(TAG, i + ", " + i1 + ", " + i2);
}
}, year, month, day);
datePickerDialog.getDatePicker().setMinDate(tomorrowMilliseconds);
datePickerDialog.getDatePicker().setMaxDate(futureMilliseconds);
datePickerDialog.show();
}
只是好奇,如果你找到了解決這個?我有同樣的問題。我無法選擇最後的可選日期(即使它顯示可選)。奇怪的是,它在虛擬設備上工作得很好,但不是我的實際手機。 – dschuett
這似乎是特定於Android的某些版本。在我的情況下,三星Galaxy Tab 4運行Android 5.1.1。從我讀過的內容來看,這可能適用於所有的棒棒糖設備。 –