Jihin Raju Jihin Raju - 1 month ago 22
Java Question

datepickerdialog hide calendar and change my date picker view to standard mode

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

Answer

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.