In datePickerDialog how to replace the cancel button by a clear button ? and catch the event when we click on it ?
Asked
Active
Viewed 1,306 times
2 Answers
0
You can build your own dialog with the builder:
new DatePickerDialog.Builder(this).setNegativeButton("Clear", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// they hit the clear button
}
});

anomeric
- 688
- 5
- 17
0
This should solve your requirement:
DatePickerDialog datePickerDialog = new DatePickerDialog(
this, null, 2000, 1, 1);
datePickerDialog.setButton(android.content.DialogInterface.BUTTON_NEGATIVE,
getString(R.string.your_text), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// todo on click
}
});
datePickerDialog.show();

Angel Kjos
- 1,951
- 1
- 12
- 12
-
thanks Angel, this work like a charm, just one question using this code i have this design: https://i.stack.imgur.com/gsPyb.png but i would like to keep the design as in the picture i show in my question – Aug 03 '17 at 18:44
-
The style of the DatePickerDialog is very dependent on the application theme and the OS version. The style you are seeing is a Material design DatePicker and is most probably coming from the AppCompat theme. Check your styles.xml file and see which theme you have defined for your application. You can change the style by tweaking the Theme attributes, there's also another Stackoverflow question with details about DatePicker style here: https://stackoverflow.com/questions/30239627/how-to-change-the-style-of-date-picker-in-android – Angel Kjos Aug 03 '17 at 20:30