I am writing an application which contains a DatePickerDialog
and it does not show the negative/positive buttons.
Here is one demonstration of problem with a title and a message (which shows no buttons):
This is the code which generates the picker:
DatePickerDialog dpd = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
Log.i(TAG,"onDateSet");
readingDateTv.setText(MainActivity.sdf.format(c.getTime()));
readingDateTv.setBackgroundColor(Color.argb(0x80, 0xff, 0x99, 0x99));
notifyListeners();
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
dpd.setTitle("Reading");
dpd.setMessage("Enter Reading Date");
dpd.show();
This appears to be an issue with screen sizes, the DatePickerDialog
layout and specifically the message
field. So the general question: is this a bug with the DatePickerDialog
.
As this question and investigation has evolved it becomes obvious this is a screen size issue with the DatePickerDialog
and in particular how the message
field is handled in layout. (The message
field should appear as a subtitle (smaller font than title and under the title).
I include various screen results (from emulators) to demonstrate the problem.
This is the code which generates the picker:
DatePickerDialog dpd = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
Log.i(TAG,"onDateSet");
readingDateTv.setText(MainActivity.sdf.format(c.getTime()));
readingDateTv.setBackgroundColor(Color.argb(0x80, 0xff, 0x99, 0x99));
notifyListeners();
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
dpd.setTitle("Reading");
dpd.setMessage("Enter Reading Date");
dpd.show();
The above images are from an emulated Galaxy Nexus API 25 sw320dp
. When I run the app on an emulated Nexus 7 API 25 sw600dp
it appears fine :
I then created a ldpi
emulator (120dp density and 240x400 screen size) to see how it handles what is considered the extreme low end of screen size and densities.
The results are below and show that, when no message
is defined for the dialog, a scroll bar exists and buttons - but when a message
is defined a scroll bar exists and no buttons.
( [LEFT - no message] CORRECT ) ( [RIGHT - with message] WRONG no buttons )
So my conclusion is this is a bug with the layout of DatePickerDialog
for small screens with a message. And so the solution for me is not use the message attribute.
For cases where a message
is required and it is required to handle small screen sizes, then a custom layout for a custom date picker dialog is likely the only option.