[MaterialDatePicker] API to disable dialog auto dismiss
See original GitHub issueIs your feature request related to a problem? Please describe.
I use a MaterialDatePicker.Builder.dateRangePicker()
. When the user clicks the save button, the dialog is automatically dismissed. I don’t want that, in my use case I need the dialog to be dismissed by the user with the back button or programatically.
Describe the solution you’d like
I request an official API to disable auto dismiss when save button is clicked.
Something similar to this. On AlertDialog
, we can get the positive button and set the on click listener on it, thus preventing the default behavior.
Describe alternatives you’ve considered I made a hack:
val picker=MaterialDatePicker.Builder.dateRangePicker()
.build()
Handler().postDelayed({
//hack - disable dismiss on confirm button click
val confirmButton=picker::class.java.declaredFields
.find { field -> field.name=="confirmButton" }
?.let { field ->
field.isAccessible=true
field.get(picker) as? Button
}
confirmButton?.setOnClickListener {
val interval=picker.selection as Pair<Long?, Long?>
doSomething(interval)
}
}, 1000)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Disable Cancel button in Android's MaterialDatePicker
My use case is that user cannot dismiss the DatePicker Dialog without selecting the date. MaterialDatePicker.
Read more >MaterialDatePicker - Android Developers
A Dialog with a header, MaterialCalendar, and set of actions. ... whenever the DialogFragment is dismissed, no matter how it is dismissed.
Read more >DatePicker API - Material-UI Pickers
Name Type Default
onChange * (date: DateIOType) => void
value * ParsableDate
allowKeyboardControl boolean true
Read more >Datepicker | Angular Material
API reference for Angular Material datepicker ... Component responsible for managing the date range picker popup/dialog. Selector: mat-date-range-picker.
Read more >showDatePicker function - material library - Dart API
Shows a dialog containing a Material Design date picker. ... This sample demonstrates how to create a restorable Material date picker.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the recommended practice here will be overriding the dismiss() method and decide if you want to dismiss the picker by setting a flag in button listeners.
Another option is you can use findViewById(R.id.confirm_button) instead of reflection, which is less prone to the internal change of the library.
I’ll close the request for now since it’s an intended behavior and there is a reliable way to bypass it. : )
I always used that hack with reflection as a workaround. regarding your issue, I guess you could use the same hack: