MaterialDatePicker
public
final
class
MaterialDatePicker
extends DialogFragment
java.lang.Object | |||
↳ | androidx.fragment.app.Fragment | ||
↳ | androidx.fragment.app.DialogFragment | ||
↳ | com.google.android.material.datepicker.MaterialDatePicker<S> |
A Dialog
with a header, MaterialCalendar, and set of actions.
For more information, see the component developer guidance and design guidelines.
Summary
Nested classes | |
---|---|
class |
MaterialDatePicker.Builder<S>
Used to create MaterialDatePicker instances with default and overridden settings |
Constants | |
---|---|
int |
INPUT_MODE_CALENDAR
Date picker will start with calendar view. |
int |
INPUT_MODE_TEXT
Date picker will start with input text view. |
Inherited constants |
---|
Public constructors | |
---|---|
MaterialDatePicker()
|
Public methods | |
---|---|
boolean
|
addOnCancelListener(DialogInterface.OnCancelListener onCancelListener)
The supplied listener is called when the user cancels the picker via back button or a touch outside the view. |
boolean
|
addOnDismissListener(DialogInterface.OnDismissListener onDismissListener)
The supplied listener is called whenever the DialogFragment is dismissed, no matter how it is dismissed. |
boolean
|
addOnNegativeButtonClickListener(View.OnClickListener onNegativeButtonClickListener)
The supplied listener is called when the user clicks the cancel button. |
boolean
|
addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)
The supplied listener is called when the user confirms a valid selection. |
void
|
clearOnCancelListeners()
Removes all listeners added via |
void
|
clearOnDismissListeners()
Removes all listeners added via |
void
|
clearOnNegativeButtonClickListeners()
Removes all listeners added via |
void
|
clearOnPositiveButtonClickListeners()
Removes all listeners added via |
String
|
getHeaderText()
Returns the text to display at the top of the The text is updated when the Dialog launches and on user clicks. |
int
|
getInputMode()
Returns the current MaterialDatePicker.InputMode. |
S
|
getSelection()
Returns an |
void
|
onCancel(DialogInterface dialogInterface)
|
void
|
onCreate(Bundle bundle)
|
Dialog
|
onCreateDialog(Bundle bundle)
|
View
|
onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
|
void
|
onDismiss(DialogInterface dialogInterface)
|
void
|
onSaveInstanceState(Bundle bundle)
|
void
|
onStart()
|
void
|
onStop()
|
boolean
|
removeOnCancelListener(DialogInterface.OnCancelListener onCancelListener)
Removes a listener previously added via |
boolean
|
removeOnDismissListener(DialogInterface.OnDismissListener onDismissListener)
Removes a listener previously added via |
boolean
|
removeOnNegativeButtonClickListener(View.OnClickListener onNegativeButtonClickListener)
Removes a listener previously added via |
boolean
|
removeOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)
Removes a listener previously added via |
static
long
|
thisMonthInUtcMilliseconds()
Returns the UTC milliseconds representing the first moment in current month in local timezone. |
static
long
|
todayInUtcMilliseconds()
Returns the UTC milliseconds representing the first moment of today in local timezone. |
Inherited methods | |
---|---|
Constants
INPUT_MODE_CALENDAR
public static final int INPUT_MODE_CALENDAR
Date picker will start with calendar view.
Constant Value: 0 (0x00000000)
INPUT_MODE_TEXT
public static final int INPUT_MODE_TEXT
Date picker will start with input text view.
Constant Value: 1 (0x00000001)
Public constructors
MaterialDatePicker
public MaterialDatePicker ()
Public methods
addOnCancelListener
public boolean addOnCancelListener (DialogInterface.OnCancelListener onCancelListener)
The supplied listener is called when the user cancels the picker via back button or a touch
outside the view. It is not called when the user clicks the cancel button. To add a listener
for use when the user clicks the cancel button, use addOnNegativeButtonClickListener(View.OnClickListener)
.
Parameters | |
---|---|
onCancelListener |
DialogInterface.OnCancelListener |
Returns | |
---|---|
boolean |
addOnDismissListener
public boolean addOnDismissListener (DialogInterface.OnDismissListener onDismissListener)
The supplied listener is called whenever the DialogFragment is dismissed, no matter how it is dismissed.
Parameters | |
---|---|
onDismissListener |
DialogInterface.OnDismissListener |
Returns | |
---|---|
boolean |
addOnNegativeButtonClickListener
public boolean addOnNegativeButtonClickListener (View.OnClickListener onNegativeButtonClickListener)
The supplied listener is called when the user clicks the cancel button.
Parameters | |
---|---|
onNegativeButtonClickListener |
View.OnClickListener |
Returns | |
---|---|
boolean |
addOnPositiveButtonClickListener
public boolean addOnPositiveButtonClickListener (MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)
The supplied listener is called when the user confirms a valid selection.
Parameters | |
---|---|
onPositiveButtonClickListener |
MaterialPickerOnPositiveButtonClickListener |
Returns | |
---|---|
boolean |
clearOnCancelListeners
public void clearOnCancelListeners ()
Removes all listeners added via addOnCancelListener(DialogInterface.OnCancelListener)
.
clearOnDismissListeners
public void clearOnDismissListeners ()
Removes all listeners added via addOnDismissListener(DialogInterface.OnDismissListener)
.
clearOnNegativeButtonClickListeners
public void clearOnNegativeButtonClickListeners ()
Removes all listeners added via addOnNegativeButtonClickListener(View.OnClickListener)
.
clearOnPositiveButtonClickListeners
public void clearOnPositiveButtonClickListeners ()
Removes all listeners added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener super S>)
.
getHeaderText
public String getHeaderText ()
Returns the text to display at the top of the DialogFragment
The text is updated when the Dialog launches and on user clicks.
Returns | |
---|---|
String |
getInputMode
public int getInputMode ()
Returns the current MaterialDatePicker.InputMode.
Returns | |
---|---|
int |
getSelection
public S getSelection ()
Returns an S
instance representing the selection or null if the user has not confirmed
a selection.
Returns | |
---|---|
S |
onCancel
public void onCancel (DialogInterface dialogInterface)
Parameters | |
---|---|
dialogInterface |
DialogInterface |
onCreate
public void onCreate (Bundle bundle)
Parameters | |
---|---|
bundle |
Bundle |
onCreateDialog
public Dialog onCreateDialog (Bundle bundle)
Parameters | |
---|---|
bundle |
Bundle |
Returns | |
---|---|
Dialog |
onCreateView
public View onCreateView (LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
Parameters | |
---|---|
layoutInflater |
LayoutInflater |
viewGroup |
ViewGroup |
bundle |
Bundle |
Returns | |
---|---|
View |
onDismiss
public void onDismiss (DialogInterface dialogInterface)
Parameters | |
---|---|
dialogInterface |
DialogInterface |
onSaveInstanceState
public void onSaveInstanceState (Bundle bundle)
Parameters | |
---|---|
bundle |
Bundle |
onStart
public void onStart ()
onStop
public void onStop ()
removeOnCancelListener
public boolean removeOnCancelListener (DialogInterface.OnCancelListener onCancelListener)
Removes a listener previously added via addOnCancelListener(DialogInterface.OnCancelListener)
.
Parameters | |
---|---|
onCancelListener |
DialogInterface.OnCancelListener |
Returns | |
---|---|
boolean |
removeOnDismissListener
public boolean removeOnDismissListener (DialogInterface.OnDismissListener onDismissListener)
Removes a listener previously added via addOnDismissListener(DialogInterface.OnDismissListener)
.
Parameters | |
---|---|
onDismissListener |
DialogInterface.OnDismissListener |
Returns | |
---|---|
boolean |
removeOnNegativeButtonClickListener
public boolean removeOnNegativeButtonClickListener (View.OnClickListener onNegativeButtonClickListener)
Removes a listener previously added via addOnNegativeButtonClickListener(View.OnClickListener)
.
Parameters | |
---|---|
onNegativeButtonClickListener |
View.OnClickListener |
Returns | |
---|---|
boolean |
removeOnPositiveButtonClickListener
public boolean removeOnPositiveButtonClickListener (MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)
Removes a listener previously added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener super S>)
.
Parameters | |
---|---|
onPositiveButtonClickListener |
MaterialPickerOnPositiveButtonClickListener |
Returns | |
---|---|
boolean |
thisMonthInUtcMilliseconds
public static long thisMonthInUtcMilliseconds ()
Returns the UTC milliseconds representing the first moment in current month in local timezone.
Returns | |
---|---|
long |
todayInUtcMilliseconds
public static long todayInUtcMilliseconds ()
Returns the UTC milliseconds representing the first moment of today in local timezone.
Returns | |
---|---|
long |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-12-15 UTC.