How To Use New Material Date Picker for Android

How To Use New Material Date Picker for Android

Hello everyone, Google recently released MaterialDatePicker: a useful new component that complies with the material design guidelines(https://material.io/components/pickers/#usage). This new component has a very interesting feature that allows you to select a date range instead of the old flow of selecting two dates: one “from” and one "to, i.e the component can be used as a DatePicker and a DateRangePicker. I was very excited about this and i wanted to use this in an update to a project i work on: to improve the user experience, sadly i could not find any examples or tutorials on using this lovely new component. So, I decided to make one, in this article I will be outlining the steps I took to make use of the MaterialDatePicker. This would be a really short article since, the MaterialDatePicker is really very easy to use.

That’s a super cool post! I’m super excited about this new picker.

But it will be nice if you can define the picker to only select those fields of you are interested for.
For example. Right now i only want to request the month and the year, and i can’t find the way to hide the calendar and the day in the title. Is this possible with the new MaterialDatePicker?

Thanks

To be honest i am not sure if the picker can be setup to behave in that way. But i know you can set constraints on the Picker’s nature using CalenderConstraints.Builder, i am not just not certain if theses constraints currently include field limitations

Thanks for your answer. It’s a real pity that it can’t be configured like that. It will make the picker more comfortable to create new functionalities.

In my case, I solved it using the spinner picker desing (deprecated right now) and hiding fields, but i don’t really like that.

Hopefully it would come in on a later version

How do I change the default date format of the picker?