material-components-android
material-components-android copied to clipboard
[Feature Request] Add Neutral Button to MaterialDatePicker
Use case: There are times when one wants to clear a selected date (i.e. I have a task with a due date, I want to use the MaterialDatePicker to display the current date, pick a new date OR clear the selected date.
The first two are currently supported, the 3rd requires either the ability to extend the class and override the onCreateView (not possible because the class is final) or adding support for a Neutral button.
Thanks for this feature request! This is currently awaiting design feedback
Any updates on this?
Sample implementation. I did this by copying the full class into my codebase and adding neutral button support.

any update?
I would also love to see such an option, for the same reason as @DvTonder
Same, any updates? We wanted to migrate from DatePickerDialog to MaterialDatePicker but need this button so I guess not for now.
Any update? I've seen Google Apps using this pattern which made me think it was already implemented, but seems none of the google apps are using this MaterialDatePicker component. Am I missing some configuration?
Hi folks,
Our designer is working on refining the date picker design. They are aware of the request and is adding the neutral button into their design. Please stay tuned.
I've created a new pull request that rebases the changes against the most recent Material Components code base as of 18 December, 2023.
Please please please please please can we have this? Jitpack.io is no longer building successfully the forked repo since Flamingo / Gradle 8 (something changed outside of my code) and my development has come to a halt. I cannot build my app any more
Hi, the major problem of this feature request (and the relevant PR you made) is that it doesn't support the full screen mode. (Actually with your PR it crashes when you open the date picker in full screen.)
We've raised to our designers for their opinion about where to put this neutral button on the full screen picker but we don't really have a good answer yet.
If you really need this feature, can you try to support fullscreen picker as well. And I can grab a screenshot to ask if our designers are ok with that (at least for now, before we have a final design)?
Sorry for the long waiting!
I will look into the full screen picker crash and update the pull request when fixed
I have updated the code to include the clear button on the full screen picker as well. It was missing from the layout which caused an NPE. I picked the most logical spot for the clear button on the UI

Hi, it has been 2 months since the update to the full screen view. Any updates?
Hi,
So our designer provided a different design guidelines regarding the full screen mode, which requires a bit work to implement it and I apologize that we don't really have the capacity for that at the moment.
Can the design guidelines be shared so I can try and implement it?
On Thu, Jun 29, 2023, 10:50 drchen @.***> wrote:
Hi,
So our designer provided a different design guidelines regarding the full screen mode, which requires a bit work to implement it and I apologize that we don't really have the capacity for that at the moment.
— Reply to this email directly, view it on GitHub https://github.com/material-components/material-components-android/issues/1332#issuecomment-1613319874, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHJ232ZPJIDYKFHDSORCGTXNWI2HANCNFSM4NKHGRAA . You are receiving this because you were mentioned.Message ID: <material-components/material-components-android/issues/1332/1613319874@ github.com>
That will be great! Thank you so much!
The design suggestion is following the spec here: https://m3.material.io/components/date-pickers/specs#f25f68b7-1bb5-4248-829e-fe3cd3499dab And adding only the clear button to the bottom button bar (which doesn't really exist in the current implementation).
To confirm:
Looking at the spec, it is basically adding 'cancel' and 'ok' (and 'clear) buttons in a button bar at the bottom of the full screen view, mimicking a dialog. The current full screen view does not have that.
Should be relatively easy to do, I think
On Thu, Jun 29, 2023, 11:08 drchen @.***> wrote:
That will be great! Thank you so much!
The design suggestion is following the spec here:
https://m3.material.io/components/date-pickers/specs#f25f68b7-1bb5-4248-829e-fe3cd3499dab And adding only the clear button to the bottom button bar.
— Reply to this email directly, view it on GitHub https://github.com/material-components/material-components-android/issues/1332#issuecomment-1613352550, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHJ232QATTEWYSKMF6OHYLXNWLANANCNFSM4NKHGRAA . You are receiving this because you were mentioned.Message ID: <material-components/material-components-android/issues/1332/1613352550@ github.com>
That's correct. : )
Thank you so much for contributing on this!
FYI after the change is made it may take a while internally for us to figure out a strategy to update the change to google apps, which has a lot of document work to do.
I would suggest to introduce this new style as a separate theme/style (and ignore neutral button in the original theme/style) which should make migration easier on our end.
@drchen can you confirm this is how they intend the design to be?
I've implemented it though I still have to figure out how to do the style/theme stuff you mention. Not entirely sure how to tackle that yet... Any guidance would be appreciated
[EDITED with updated screenshots. I implemented the padding/margins as indicated in design]
I'm using the MaterialDatePicker as a date range picker, and I tried setting setNegativeButtonText and addOnNegativeButtonClickListener to no avail, no neutral button shows up in the interface. So it's either a bug, or the method does nothing when the date picker is a range one, which is quite misleading...
What's the expected behavior for these methods?
I'd like the user to be able to clear the chosen dates. It would be great to have a neutral button for the date range picker too. I can make a feature request once I'm certain that this is not actually a bug, or a bug ticket then
I will check the code. I'm not sure if I implemented the clearing for the Range picker.
On Mon, Aug 21, 2023 at 4:40 PM fabiorbap @.***> wrote:
I'm using the MaterialDatePicker as a date range picker, and I tried setting setNegativeButtonText and addOnNegativeButtonClickListener to no avail, no neutral button shows up in the interface. So it's either a bug, or the method does nothing when the date picker is a range one, which is quite misleading... What's the expected behavior for these methods? I'd like the user to be able to clear the chosen dates [image: Screenshot 2023-08-21 at 17 39 50] https://user-images.githubusercontent.com/12398089/262148708-9038d94d-8d55-4e78-b1fe-525b2c25b51e.png
— Reply to this email directly, view it on GitHub https://github.com/material-components/material-components-android/issues/1332#issuecomment-1687012981, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHJ235KGX47DBWKP5BF6W3XWPBT3ANCNFSM4NKHGRAA . You are receiving this because you were mentioned.Message ID: <material-components/material-components-android/issues/1332/1687012981@ github.com>
I added the full screen version code to this pull request -> https://github.com/material-components/material-components-android/pull/3145 but I still have to do the 'style' enabled version