I am getting an extra header for DatePickerDialog as shown in the screenshot below. However, my question is not about how to remove this extra header but it's about the cause behind this. First of all, let me copy and paste my DatePickerDialog
code even though it's fairly simple and straightforward.
//initialize dialog
datePickerDialog = new DatePickerDialog(
getActivity(),
R.style.DatePickerTheme,
this,
today.get(Calendar.YEAR),
today.get(Calendar.MONTH),
today.get(Calendar.DAY_OF_MONTH));
//set dialog maximum date
datePickerDialog.getDatePicker().setMaxDate(maxDate.getTimeInMillis());
//set dialog minimum possible date
datePickerDialog.getDatePicker().setMinDate(minDate.getTimeInMillis());
datePickerDialog.show();
As you can see from the attached screenshot, there is an extra title(or header) in the date picker. I was trying to google for solutions and potentially understand the cause behind. I found there are already 2 similar questions(q1, q2) asked on stackoverflow about extra title and the solution is also pretty clear and straightward. We can do either:
datePickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
ordatePickerDiaglog.setTitle("");
to eliminate the extra title. However, no one really explained the cause behind this. Also, the most important thing is that the extra title problem only appears on Android Marshmallow, Lollipop and potentially previous versions as well but not on Android Nougat when I tested it in the emulator. I tried to trace down through the source code and inspired from one of the answer in this question asked here, someone said:
The following line of code sets your dialog title value: fromDatePickerDialog.getDatePicker().setMaxDate(d.getTime());
So I tried to look into the source code of DatePickerDialog on different version of APIs(23 and 24, especially on 23 where it has the extra title problem) but did not find that setMaxDate
is setting the extra title. I am getting to a dead end and stuck on this for a while. Can someone please point to a direction on this or share your experience if you have seen this before? Many Thanks!