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

int STYLE_NORMAL

int STYLE_NO_FRAME

int STYLE_NO_INPUT

int STYLE_NO_TITLE

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 addOnCancelListener(DialogInterface.OnCancelListener).

void clearOnDismissListeners()

Removes all listeners added via addOnDismissListener(DialogInterface.OnDismissListener).

void clearOnNegativeButtonClickListeners()

Removes all listeners added via addOnNegativeButtonClickListener(View.OnClickListener).

void clearOnPositiveButtonClickListeners()

Removes all listeners added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener).

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.

int getInputMode()

Returns the current MaterialDatePicker.InputMode.

S getSelection()

Returns an S instance representing the selection or null if the user has not confirmed a selection.

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 addOnCancelListener(DialogInterface.OnCancelListener).

boolean removeOnDismissListener(DialogInterface.OnDismissListener onDismissListener)

Removes a listener previously added via addOnDismissListener(DialogInterface.OnDismissListener).

boolean removeOnNegativeButtonClickListener(View.OnClickListener onNegativeButtonClickListener)

Removes a listener previously added via addOnNegativeButtonClickListener(View.OnClickListener).

boolean removeOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)

Removes a listener previously added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener).

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

void dismiss()
void dismissAllowingStateLoss()
Dialog getDialog()
boolean getShowsDialog()
int getTheme()
boolean isCancelable()
void onAttach(Context arg0)
void onCancel(DialogInterface arg0)
void onCreate(Bundle arg0)
Dialog onCreateDialog(Bundle arg0)
void onDestroyView()
void onDetach()
void onDismiss(DialogInterface arg0)
LayoutInflater onGetLayoutInflater(Bundle arg0)
void onSaveInstanceState(Bundle arg0)
void onStart()
void onStop()
void onViewStateRestored(Bundle arg0)
final Dialog requireDialog()
void setCancelable(boolean arg0)
void setShowsDialog(boolean arg0)
void setStyle(int arg0, int arg1)
void setupDialog(Dialog arg0, int arg1)
void show(FragmentManager arg0, String arg1)
int show(FragmentTransaction arg0, String arg1)
void showNow(FragmentManager arg0, String arg1)
void dump(String arg0, FileDescriptor arg1, PrintWriter arg2, String[] arg3)
final boolean equals(Object arg0)
final FragmentActivity getActivity()
boolean getAllowEnterTransitionOverlap()
boolean getAllowReturnTransitionOverlap()
final Bundle getArguments()
final FragmentManager getChildFragmentManager()
Context getContext()
ViewModelProvider.Factory getDefaultViewModelProviderFactory()
Object getEnterTransition()
Object getExitTransition()
final FragmentManager getFragmentManager()
final Object getHost()
final int getId()
LayoutInflater getLayoutInflater(Bundle arg0)
final LayoutInflater getLayoutInflater()
Lifecycle getLifecycle()
LoaderManager getLoaderManager()
final Fragment getParentFragment()
final FragmentManager getParentFragmentManager()
Object getReenterTransition()
final Resources getResources()
final boolean getRetainInstance()
Object getReturnTransition()
final SavedStateRegistry getSavedStateRegistry()
Object getSharedElementEnterTransition()
Object getSharedElementReturnTransition()
final String getString(int arg0, Object... arg1)
final String getString(int arg0)
final String getTag()
final Fragment getTargetFragment()
final int getTargetRequestCode()
final CharSequence getText(int arg0)
boolean getUserVisibleHint()
View getView()
LifecycleOwner getViewLifecycleOwner()
LiveData<LifecycleOwner> getViewLifecycleOwnerLiveData()
ViewModelStore getViewModelStore()
final boolean hasOptionsMenu()
final int hashCode()
static Fragment instantiate(Context arg0, String arg1)
static Fragment instantiate(Context arg0, String arg1, Bundle arg2)
final boolean isAdded()
final boolean isDetached()
final boolean isHidden()
final boolean isInLayout()
final boolean isMenuVisible()
final boolean isRemoving()
final boolean isResumed()
final boolean isStateSaved()
final boolean isVisible()
void onActivityCreated(Bundle arg0)
void onActivityResult(int arg0, int arg1, Intent arg2)
void onAttach(Activity arg0)
void onAttach(Context arg0)
void onAttachFragment(Fragment arg0)
void onConfigurationChanged(Configuration arg0)
boolean onContextItemSelected(MenuItem arg0)
void onCreate(Bundle arg0)
Animation onCreateAnimation(int arg0, boolean arg1, int arg2)
Animator onCreateAnimator(int arg0, boolean arg1, int arg2)
void onCreateContextMenu(ContextMenu arg0, View arg1, ContextMenu.ContextMenuInfo arg2)
void onCreateOptionsMenu(Menu arg0, MenuInflater arg1)
View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2)
void onDestroy()
void onDestroyOptionsMenu()
void onDestroyView()
void onDetach()
LayoutInflater onGetLayoutInflater(Bundle arg0)
void onHiddenChanged(boolean arg0)
void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2)
void onInflate(Context arg0, AttributeSet arg1, Bundle arg2)
void onLowMemory()
void onMultiWindowModeChanged(boolean arg0)
boolean onOptionsItemSelected(MenuItem arg0)
void onOptionsMenuClosed(Menu arg0)
void onPause()
void onPictureInPictureModeChanged(boolean arg0)
void onPrepareOptionsMenu(Menu arg0)
void onPrimaryNavigationFragmentChanged(boolean arg0)
void onRequestPermissionsResult(int arg0, String[] arg1, int[] arg2)
void onResume()
void onSaveInstanceState(Bundle arg0)
void onStart()
void onStop()
void onViewCreated(View arg0, Bundle arg1)
void onViewStateRestored(Bundle arg0)
void postponeEnterTransition()
final void postponeEnterTransition(long arg0, TimeUnit arg1)
final <I, O> ActivityResultLauncher<I> registerForActivityResult(ActivityResultContract<I, O> arg0, ActivityResultCallback<O> arg1)
final <I, O> ActivityResultLauncher<I> registerForActivityResult(ActivityResultContract<I, O> arg0, ActivityResultRegistry arg1, ActivityResultCallback<O> arg2)
void registerForContextMenu(View arg0)
final void requestPermissions(String[] arg0, int arg1)
final FragmentActivity requireActivity()
final Bundle requireArguments()
final Context requireContext()
final FragmentManager requireFragmentManager()
final Object requireHost()
final Fragment requireParentFragment()
final View requireView()
void setAllowEnterTransitionOverlap(boolean arg0)
void setAllowReturnTransitionOverlap(boolean arg0)
void setArguments(Bundle arg0)
void setEnterSharedElementCallback(SharedElementCallback arg0)
void setEnterTransition(Object arg0)
void setExitSharedElementCallback(SharedElementCallback arg0)
void setExitTransition(Object arg0)
void setHasOptionsMenu(boolean arg0)
void setInitialSavedState(Fragment.SavedState arg0)
void setMenuVisibility(boolean arg0)
void setReenterTransition(Object arg0)
void setRetainInstance(boolean arg0)
void setReturnTransition(Object arg0)
void setSharedElementEnterTransition(Object arg0)
void setSharedElementReturnTransition(Object arg0)
void setTargetFragment(Fragment arg0, int arg1)
void setUserVisibleHint(boolean arg0)
boolean shouldShowRequestPermissionRationale(String arg0)
void startActivity(Intent arg0)
void startActivity(Intent arg0, Bundle arg1)
void startActivityForResult(Intent arg0, int arg1)
void startActivityForResult(Intent arg0, int arg1, Bundle arg2)
void startIntentSenderForResult(IntentSender arg0, int arg1, Intent arg2, int arg3, int arg4, int arg5, Bundle arg6)
void startPostponedEnterTransition()
String toString()
void unregisterForContextMenu(View arg0)
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait(long arg0, int arg1)
final void wait(long arg0)
final void wait()
abstract void onCancel(DialogInterface arg0)
abstract void onDismiss(DialogInterface arg0)
abstract void onConfigurationChanged(Configuration arg0)
abstract void onLowMemory()
abstract void onCreateContextMenu(ContextMenu arg0, View arg1, ContextMenu.ContextMenuInfo arg2)
abstract Lifecycle getLifecycle()
abstract ViewModelStore getViewModelStore()
default CreationExtras getDefaultViewModelCreationExtras()
abstract ViewModelProvider.Factory getDefaultViewModelProviderFactory()
abstract SavedStateRegistry getSavedStateRegistry()
abstract <I, O> ActivityResultLauncher<I> registerForActivityResult(ActivityResultContract<I, O> arg0, ActivityResultCallback<O> arg1)
abstract <I, O> ActivityResultLauncher<I> registerForActivityResult(ActivityResultContract<I, O> arg0, ActivityResultRegistry arg1, ActivityResultCallback<O> arg2)

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).

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).

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