4

I want to change my date picker view to standard mode

From

enter image description here

To

enter image description here

My code is

dateOfBirthET = (EditText) findViewById(R.id.dateOfBirth);
        //setting dateSetListener
        final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                                  int dayOfMonth) {
                // TODO Auto-generated method stub
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabel();
                updateLabelToSave();
            }

        };

        //setting onClickListener on setDate
        dateOfBirthET.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                DatePickerDialog dpd = new DatePickerDialog(RegisterActivity.this, date,
                        myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH));


                //setting maxDate on tempCal
                long maxDate = new Date().getTime();
                tempCal.setTimeInMillis(maxDate);
                tempCal.set(Calendar.YEAR, tempCal.get(Calendar.YEAR) - 16);

                dpd.getDatePicker().setMaxDate(tempCal.getTimeInMillis());

                dpd.show();
            }
        });

    }

I am tried this code also but not working

dpd.getDatePicker().setCalendarViewShown(false);
byteC0de
  • 5,153
  • 5
  • 33
  • 66
  • Refer this link http://stackoverflow.com/questions/28740657/datepicker-dialog-without-calendar-visualization-in-lollipop-spinner-mode – Febi M Felix Oct 21 '16 at 06:56

2 Answers2

1

You just need to change theme you want while creating DatePickerDialog instance

DatePickerDialog dpd = new DatePickerDialog(RegisterActivity.this, android.R.style.Theme_Holo_Dialog ,date,
                        myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH));

Working for me tested android 6.0 marshmallow.

byteC0de
  • 5,153
  • 5
  • 33
  • 66
Swapnil
  • 2,409
  • 4
  • 26
  • 48
0

From the setCalendarViewShown doc it says

Calling this method has no effect when the DatePicker_datePickerMode attribute is set to calendar.

And as of Android L, with the Material theme selected, the default layout of android:datePickerMode is calendar (see here)

So if you want to change your DatePickerDialog to spiner style, you must change android:datePickerMode

And now I see datePickerMode can not change programmatically, it can only change by config XML like

<DatePicker
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:datePickerMode="spinner"
    />

Therefore I think you should create a custom your DatePickerDilog layout

Linh
  • 57,942
  • 23
  • 262
  • 279