Added in API level 1

DatePicker


open class DatePicker : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ android.widget.DatePicker

Provides a widget for selecting a date.

When the android.R.styleable#DatePicker_datePickerMode attribute is set to spinner, the date can be selected using year, month, and day spinners or a CalendarView. The set of spinners and the calendar view are automatically synchronized. The client can customize whether only the spinners, or only the calendar view, or both to be displayed.

When the android.R.styleable#DatePicker_datePickerMode attribute is set to calendar, the month and day can be selected using a calendar-style view while the year can be selected separately using a list.

See the Pickers guide.

For a dialog using this view, see android.app.DatePickerDialog.

Summary

Nested classes
abstract

The callback used to indicate the user changed the date.

XML attributes
android:calendarTextColor The text color list of the calendar.
android:calendarViewShown Whether the calendar view is shown.
android:datePickerMode Defines the look of the widget.
android:dayOfWeekBackground The background color for the header's day of week.
android:dayOfWeekTextAppearance The text color for the header's day of week.
android:endYear The last year (inclusive), for example "2010".
android:headerBackground The background for the selected date header.
android:headerDayOfMonthTextAppearance The text appearance for the day of month (ex. 28) in the selected date header.
android:headerMonthTextAppearance The text appearance for the month (ex. May) in the selected date header.
android:headerYearTextAppearance The text appearance for the year (ex. 2014) in the selected date header.
android:maxDate The maximal date shown by this calendar view in mm/dd/yyyy format.
android:minDate The minimal date shown by this calendar view in mm/dd/yyyy format.
android:spinnersShown Whether the spinners are shown.
android:startYear The first year (inclusive), for example "1940".
android:yearListItemTextAppearance The list year's text appearance in the list.
android:yearListSelectorColor The list year's selected circle color in the list.
Inherited XML attributes
Inherited constants
Public constructors
DatePicker(context: Context!)

DatePicker(context: Context!, attrs: AttributeSet!)

DatePicker(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

DatePicker(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

open Unit

open CharSequence!

open Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

open AutofillValue?

open CalendarView!

Returns the CalendarView used by this picker.

open Boolean

Returns whether the CalendarView is shown.

open Int

open Int

Gets the first day of week.

open Long

Gets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

open Long

Gets the minimal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

open Int

open Boolean

Returns whether the spinners are shown.

open Int

open Unit
init(year: Int, monthOfYear: Int, dayOfMonth: Int, onDateChangedListener: DatePicker.OnDateChangedListener!)

Initialize the state.

open Boolean

open Unit

Sets whether the CalendarView is shown.

open Unit
setEnabled(enabled: Boolean)

open Unit
setFirstDayOfWeek(firstDayOfWeek: Int)

Sets the first day of week.

open Unit
setMaxDate(maxDate: Long)

Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

open Unit
setMinDate(minDate: Long)

Sets the minimal date supported by this NumberPicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

open Unit

Set the callback that indicates the date has been adjusted by the user.

open Unit

Sets whether the spinners are shown.

open Unit
updateDate(year: Int, month: Int, dayOfMonth: Int)

Update the current date.

Protected methods
open Unit

open Unit

open Unit

open Parcelable?

Inherited functions
Inherited properties

XML attributes

android:calendarTextColor

android:calendarTextColor
The text color list of the calendar.

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:calendarViewShown

android:calendarViewShown
Whether the calendar view is shown. Only valid for "spinner" mode.

May be a boolean value, such as "true" or "false".

android:datePickerMode

android:datePickerMode
Defines the look of the widget. Prior to the L release, the only choice was spinner. As of L, with the Material theme selected, the default layout is calendar, but this attribute can be used to force spinner to be used instead.

Must be one of the following constant values.

Constant Value Description
calendar 2 Date picker with calendar to select the date.
spinner 1 Date picker with spinner controls to select the date.

android:dayOfWeekBackground

android:dayOfWeekBackground
The background color for the header's day of week. {@deprecated No longer displayed.}

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:dayOfWeekTextAppearance

android:dayOfWeekTextAppearance
The text color for the header's day of week. {@deprecated No longer displayed.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:endYear

android:endYear
The last year (inclusive), for example "2010". {@deprecated Use maxDate instead.}

May be an integer value, such as "100".

android:headerBackground

android:headerBackground
The background for the selected date header.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:headerDayOfMonthTextAppearance

android:headerDayOfMonthTextAppearance
The text appearance for the day of month (ex. 28) in the selected date header. {@deprecated Use headerTextColor instead.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:headerMonthTextAppearance

android:headerMonthTextAppearance
The text appearance for the month (ex. May) in the selected date header. {@deprecated Use headerTextColor instead.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:headerYearTextAppearance

android:headerYearTextAppearance
The text appearance for the year (ex. 2014) in the selected date header. {@deprecated Use headerTextColor instead.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:maxDate

android:maxDate
The maximal date shown by this calendar view in mm/dd/yyyy format.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:minDate

android:minDate
The minimal date shown by this calendar view in mm/dd/yyyy format.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:spinnersShown

android:spinnersShown
Whether the spinners are shown. Only valid for "spinner" mode.

May be a boolean value, such as "true" or "false".

android:startYear

android:startYear
The first year (inclusive), for example "1940". {@deprecated Use minDate instead.}

May be an integer value, such as "100".

android:yearListItemTextAppearance

android:yearListItemTextAppearance
The list year's text appearance in the list. {@deprecated Use yearListTextColor. }

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:yearListSelectorColor

android:yearListSelectorColor
The list year's selected circle color in the list. {@deprecated No longer displayed.}

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

Public constructors

DatePicker

Added in API level 1
DatePicker(context: Context!)

DatePicker

Added in API level 1
DatePicker(
    context: Context!,
    attrs: AttributeSet!)

DatePicker

Added in API level 1
DatePicker(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

DatePicker

Added in API level 21
DatePicker(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

autofill

Added in API level 26
open fun autofill(value: AutofillValue!): Unit
Parameters
value AutofillValue!: value to be autofilled.

dispatchProvideAutofillStructure

Added in API level 26
open fun dispatchProvideAutofillStructure(
    structure: ViewStructure,
    flags: Int
): Unit
Parameters
structure ViewStructure: fill in with structured view data for autofill purposes. This value cannot be null.
flags Int: Value is either 0 or android.view.View#AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getAutofillType

Added in API level 26
open fun getAutofillType(): Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

By default returns AUTOFILL_TYPE_NONE, but views should override it to properly support the Autofill Framework.

Return
Int Value is android.view.View#AUTOFILL_TYPE_NONE, android.view.View#AUTOFILL_TYPE_TEXT, android.view.View#AUTOFILL_TYPE_TOGGLE, android.view.View#AUTOFILL_TYPE_LIST, or android.view.View#AUTOFILL_TYPE_DATE

getAutofillValue

Added in API level 26
open fun getAutofillValue(): AutofillValue?

getCalendarView

Added in API level 12
Deprecated in API level 24
open fun getCalendarView(): CalendarView!

Deprecated: Not supported by Material-style calendar mode

Returns the CalendarView used by this picker.

Note: This method throws an UnsupportedOperationException when the android.R.styleable#DatePicker_datePickerMode attribute is set to calendar.

Return
CalendarView! the calendar view
Exceptions
java.lang.UnsupportedOperationException if called when the picker is displayed in calendar mode

getCalendarViewShown

Added in API level 11
Deprecated in API level 24
open fun getCalendarViewShown(): Boolean

Deprecated: Not supported by Material-style calendar mode

Returns whether the CalendarView is shown.

Note: This method returns false when the android.R.styleable#DatePicker_datePickerMode attribute is set to calendar.

Return
Boolean true if the calendar view is shown

getDayOfMonth

Added in API level 1
open fun getDayOfMonth(): Int
Return
Int The selected day of month.

getMaxDate

Added in API level 11
open fun getMaxDate(): Long

Gets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

Note: The default maximal date is 12/31/2100.

Return
Long The maximal supported date.

getMinDate

Added in API level 11
open fun getMinDate(): Long

Gets the minimal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

Note: The default minimal date is 01/01/1900.

Return
Long The minimal supported date.

getMonth

Added in API level 1
open fun getMonth(): Int
Return
Int The selected month.

getSpinnersShown

Added in API level 11
Deprecated in API level 24
open fun getSpinnersShown(): Boolean

Deprecated: Not supported by Material-style calendar mode

Returns whether the spinners are shown.

Note: this method returns false when the android.R.styleable#DatePicker_datePickerMode attribute is set to calendar.

Return
Boolean true if the spinners are shown

getYear

Added in API level 1
open fun getYear(): Int
Return
Int The selected year.

init

Added in API level 1
open fun init(
    year: Int,
    monthOfYear: Int,
    dayOfMonth: Int,
    onDateChangedListener: DatePicker.OnDateChangedListener!
): Unit

Initialize the state. If the provided values designate an inconsistent date the values are normalized before updating the spinners.

Parameters
year Int: The initial year.
monthOfYear Int: The initial month starting from zero.
dayOfMonth Int: The initial day of the month.
onDateChangedListener DatePicker.OnDateChangedListener!: How user is notified date is changed by user, can be null.

isEnabled

Added in API level 1
open fun isEnabled(): Boolean
Return
Boolean True if this view is enabled, false otherwise.

setCalendarViewShown

Added in API level 11
Deprecated in API level 24
open fun setCalendarViewShown(shown: Boolean): Unit

Deprecated: Not supported by Material-style calendar mode

Sets whether the CalendarView is shown.

Note: Calling this method has no effect when the android.R.styleable#DatePicker_datePickerMode attribute is set to calendar.

Parameters
shown Boolean: true to show the calendar view, false to hide it

setEnabled

Added in API level 1
open fun setEnabled(enabled: Boolean): Unit
Parameters
enabled Boolean: True if this view is enabled, false otherwise.

setFirstDayOfWeek

Added in API level 21
open fun setFirstDayOfWeek(firstDayOfWeek: Int): Unit

Sets the first day of week.

Parameters
firstDayOfWeek Int: The first day of the week conforming to the CalendarView APIs.

setMaxDate

Added in API level 11
open fun setMaxDate(maxDate: Long): Unit

Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

Parameters
maxDate Long: The maximal supported date.

setMinDate

Added in API level 11
open fun setMinDate(minDate: Long): Unit

Sets the minimal date supported by this NumberPicker in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone.

Parameters
minDate Long: The minimal supported date.

setOnDateChangedListener

Added in API level 26
open fun setOnDateChangedListener(onDateChangedListener: DatePicker.OnDateChangedListener!): Unit

Set the callback that indicates the date has been adjusted by the user.

Parameters
onDateChangedListener DatePicker.OnDateChangedListener!: How user is notified date is changed by user, can be null.

setSpinnersShown

Added in API level 11
Deprecated in API level 24
open fun setSpinnersShown(shown: Boolean): Unit

Deprecated: Not supported by Material-style calendar mode

Sets whether the spinners are shown.

Calling this method has no effect when the android.R.styleable#DatePicker_datePickerMode attribute is set to calendar.

Parameters
shown Boolean: true to show the spinners, false to hide them

updateDate

Added in API level 1
open fun updateDate(
    year: Int,
    month: Int,
    dayOfMonth: Int
): Unit

Update the current date.

Parameters
year Int: The year.
month Int: The month which is starting from zero.
dayOfMonth Int: The day of the month.

Protected methods

dispatchRestoreInstanceState

Added in API level 1
protected open fun dispatchRestoreInstanceState(container: SparseArray<Parcelable!>!): Unit
Parameters
container SparseArray<Parcelable!>!: The SparseArray which holds previously saved state.

onConfigurationChanged

Added in API level 8
protected open fun onConfigurationChanged(newConfig: Configuration!): Unit
Parameters
newConfig Configuration!: The new resource configuration.

onRestoreInstanceState

Added in API level 1
protected open fun onRestoreInstanceState(state: Parcelable!): Unit
Parameters
state Parcelable!: The frozen state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 1
protected open fun onSaveInstanceState(): Parcelable?
Return
Parcelable? Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.