Вы можете создать свой собственный Dialog
с помощью NumberPicker
, но если вы все еще хотите использовать DatePickerDialog
, это должно работать:
DatePickerDialog mDatePicker = new DatePickerDialog(MainActivity.this, android.R.style.Theme_Holo_Light_Dialog, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int selectedyear, int selectedmonth, int selectedday) {
// Stuff
}
}, mYear, mMonth, mDayOfMonth) {
final int month = getContext().getResources().getIdentifier("android:id/month", null, null);
final String[] monthNumbers = new String[]{ "01","02","03","04","05","06","07","08","09","10","11","12"}
@Override
public void onDateChanged(@NonNull DatePicker view, int y, int m, int d) {
super.onDateChanged(view, y, m, d);
// Since DatePickerCalendarDelegate updates the month spinner too, we need to change months as numbers here also
if(month != 0){
NumberPicker monthPicker = findViewById(month);
if(monthPicker != null){
monthPicker.setDisplayedValues(monthNumbers);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Hide day spinner
int day = getContext().getResources().getIdentifier("android:id/day", null, null);
if(day != 0){
NumberPicker dayPicker = findViewById(day);
if(dayPicker != null){
dayPicker.setVisibility(View.GONE);
}
}
// Show months as Numbers
if(month != 0){
NumberPicker monthPicker = findViewById(month);
if(monthPicker != null){
monthPicker.setDisplayedValues(monthNumbers);
}
}
}
};
mDatePicker.setTitle("Select Date");
mDatePicker.show();