Datepickerdialog hide calendar and change date view mode in standard mode

I want to change my date picker view to standard mode

WITH

enter image description here

For

enter image description here

My code

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 tried this code too but didn't work

dpd.getDatePicker().setCalendarViewShown(false);
+4
source share
2 answers

You just need to change the theme you want by creating an instance of DatePickerDialog

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));

Work for me was tested on a swamp android 6.0.

+1
source

The setCalendarViewShown file says:

A call to this method does not work when the DatePicker_datePickerMode attribute is set to the calendar.

Android L, Material, android:datePickerMode - (. )

, DatePickerDialog , android:datePickerMode

, datePickerMode , config XML,

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

, DatePickerDilog

0

Source: https://habr.com/ru/post/1658400/


All Articles