List of usage examples for android.app DatePickerDialog setOnKeyListener
public void setOnKeyListener(@Nullable OnKeyListener onKeyListener)
From source file:com.simplaapliko.trips.presentation.fragment.SelectDateDialog.java
@NonNull @Override/*from ww w.ja va2s .c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final DatePickerDialog pickerDialog = new DatePickerDialog(getActivity(), this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DATE)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { pickerDialog.getDatePicker().setCalendarViewShown(false); } pickerDialog.setOnKeyListener((dialog, keyCode, event) -> { switch (keyCode) { case KeyEvent.KEYCODE_BACK: dialog.cancel(); dialog.dismiss(); return true; default: return false; } }); return pickerDialog; }