Решение: Я бы скорее предложил вам использовать другой DatePickerDialog
, который я сейчас использую и в моем проекте.Его легко использовать, выполните следующие действия:
Шаг 1: Добавьте зависимость в свой Gradle (уровень приложения):
implementation('com.wdullaer:materialdatetimepicker:3.3.0') {
exclude group: 'com.android.support'
}
Шаг 2: Используйте его в своем приложении:
try {
Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
.......
// Get Year, Month and Day from the parameter here when you select and date.
.......
}
},
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setAccentColor(ContextCompat.getColor(FilterForLoadBoardActivity.this, R.color.colorPrimary));
dpd.setMinDate(now);
dpd.show(getFragmentManager(), "Datepickerdialog");
return;
} catch (Exception e) {
e.printStackTrace();
}
Наконец: Ваш метод должен выглядеть следующим образом:
public DatePickerDialog CREATE_DATEPICKER_DIALOG() {
......
......
......
DatePickerDialog dpd;
try {
Calendar now = Calendar.getInstance();
dpd = DatePickerDialog.newInstance(new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
.......
// Get Year, Month and Day from the parameter here when you select and date.
.......
}
},
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setAccentColor(ContextCompat.getColor(FilterForLoadBoardActivity.this, R.color.colorPrimary));
dpd.setMinDate(now);
dpd.show(getFragmentManager(), "Datepickerdialog");
} catch (Exception e) {
e.printStackTrace();
}
return dpd;
}
Попробуйте, надеюсь, это поможет.