Date Pickers allow users to select a single date or date range.
The picker can be customized via the MaterialDatePicker.Builder and the CalendarConstraints.Builder. These classes allow you to
- Select the mode: single date or range of dates.
- Select the theme: dialog, fullscreen, or default (dialog for single date, fullscreen for range).
- Select the bounds: bounds can be restricted to any contiguous set of months. Defaults Janaury 1900 to December 2100.
- Select valid days: valid days can restrict selections to weekdays only. Defaults to all days as valid.
- Set a title.
- Set the month to which the picker opens (defaults to the current month if within the bounds otherwise the earliest month within the bounds).
- Set a default selection (defaults to no selection).
Examples of these customizations can be seen in the Material Picker Demo.
The picker interprets all long values as milliseconds from the UTC Epoch. If
you have access to Java 8 libraries, it is strongly recommended you use
LocalDateTime
and ZonedDateTime
; otherwise, you will need to use Calendar
.
Please see
CalendarConstraints.Builder
for more details, and use the below snippets as a guide.
Java 8:
LocalDateTime local = LocalDateTime.of(year, month, day, 0, 0);
local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
Java 7:
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(year, month, day);
c.getTimeInMillis();
You can see the current version of the Material Picker Demo in the Material Android Catalog. The demo allows you to select several configuration parameters for your date picker then launch the dialog.
The Picker Package contains the code for this component, with the main entry point being MaterialDatePicker.
Time Pickers are currently not under development.