Most visited

Recently visited

Added in API level 11

CalendarView

public class CalendarView
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.CalendarView


This class is a calendar widget for displaying and selecting dates. The range of dates supported by this calendar is configurable.

The exact appearance and interaction model of this widget may vary between OS versions and themes (e.g. Holo versus Material), but in general a user can select a date by tapping on it and can scroll or fling the calendar to a desired date.

Summary

Nested classes

interface CalendarView.OnDateChangeListener

The callback used to indicate the user changes the date. 

XML attributes

android:dateTextAppearance The text appearance for the day numbers in the calendar grid. 
android:firstDayOfWeek The first day of week according to Calendar
android:focusedMonthDateColor This is deprecated. The color for the dates of the focused month.

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

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

This corresponds to the global attribute resource symbol focusedMonthDateColor. 

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:selectedDateVerticalBar This is deprecated. Drawable for the vertical bar shown at the beginning and at the end of the selected date.

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

This corresponds to the global attribute resource symbol selectedDateVerticalBar. 

android:selectedWeekBackgroundColor This is deprecated. The background color for the selected week.

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

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

This corresponds to the global attribute resource symbol selectedWeekBackgroundColor. 

android:showWeekNumber This is deprecated. Whether do show week numbers.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol showWeekNumber. 

android:shownWeekCount This is deprecated. The number of weeks to be shown.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shownWeekCount. 

android:unfocusedMonthDateColor This is deprecated. The color for the dates of an unfocused month.

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

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

This corresponds to the global attribute resource symbol unfocusedMonthDateColor. 

android:weekDayTextAppearance The text appearance for the week day abbreviation in the calendar header. 
android:weekNumberColor This is deprecated. The color for the week numbers.

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

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

This corresponds to the global attribute resource symbol weekNumberColor. 

android:weekSeparatorLineColor This is deprecated. The color for the separator line between weeks.

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

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

This corresponds to the global attribute resource symbol weekSeparatorLineColor. 

Inherited XML attributes

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

CalendarView(Context context)
CalendarView(Context context, AttributeSet attrs)
CalendarView(Context context, AttributeSet attrs, int defStyleAttr)
CalendarView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

long getDate()

Gets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

int getDateTextAppearance()

Gets the text appearance for the calendar dates.

int getFirstDayOfWeek()

Gets the first day of week.

int getFocusedMonthDateColor()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

long getMaxDate()

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

long getMinDate()

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

Drawable getSelectedDateVerticalBar()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

int getSelectedWeekBackgroundColor()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

boolean getShowWeekNumber()

This method was deprecated in API level 24. No longer used by Material-style CalendarView.

int getShownWeekCount()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

int getUnfocusedMonthDateColor()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

int getWeekDayTextAppearance()

Gets the text appearance for the week day abbreviation of the calendar header.

int getWeekNumberColor()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

int getWeekSeparatorLineColor()

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setDate(long date, boolean animate, boolean center)

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

void setDate(long date)

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

void setDateTextAppearance(int resourceId)

Sets the text appearance for the calendar dates.

void setFirstDayOfWeek(int firstDayOfWeek)

Sets the first day of week.

void setFocusedMonthDateColor(int color)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setMaxDate(long maxDate)

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

void setMinDate(long minDate)

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

void setOnDateChangeListener(CalendarView.OnDateChangeListener listener)

Sets the listener to be notified upon selected date change.

void setSelectedDateVerticalBar(int resourceId)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setSelectedDateVerticalBar(Drawable drawable)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setSelectedWeekBackgroundColor(int color)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setShowWeekNumber(boolean showWeekNumber)

This method was deprecated in API level 24. No longer used by Material-style CalendarView.

void setShownWeekCount(int count)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setUnfocusedMonthDateColor(int color)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setWeekDayTextAppearance(int resourceId)

Sets the text appearance for the week day abbreviation of the calendar header.

void setWeekNumberColor(int color)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

void setWeekSeparatorLineColor(int color)

This method was deprecated in API level 23. No longer used by Material-style CalendarView.

Protected methods

void onConfigurationChanged(Configuration newConfig)

Called when the current configuration of the resources being used by the application have changed.

Inherited methods

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML attributes

android:dateTextAppearance

The text appearance for the day numbers in the calendar grid.

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

This corresponds to the global attribute resource symbol dateTextAppearance.

Related methods:

android:firstDayOfWeek

The first day of week according to Calendar.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol firstDayOfWeek.

Related methods:

android:focusedMonthDateColor

This is deprecated.
The color for the dates of the focused month.

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

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

This corresponds to the global attribute resource symbol focusedMonthDateColor.

Related methods:

android:maxDate

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxDate.

Related methods:

android:minDate

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minDate.

Related methods:

android:selectedDateVerticalBar

This is deprecated.
Drawable for the vertical bar shown at the beginning and at the end of the selected date.

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

This corresponds to the global attribute resource symbol selectedDateVerticalBar.

Related methods:

android:selectedWeekBackgroundColor

This is deprecated.
The background color for the selected week.

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

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

This corresponds to the global attribute resource symbol selectedWeekBackgroundColor.

Related methods:

android:showWeekNumber

This is deprecated.
Whether do show week numbers.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol showWeekNumber.

Related methods:

android:shownWeekCount

This is deprecated.
The number of weeks to be shown.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shownWeekCount.

Related methods:

android:unfocusedMonthDateColor

This is deprecated.
The color for the dates of an unfocused month.

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

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

This corresponds to the global attribute resource symbol unfocusedMonthDateColor.

Related methods:

android:weekDayTextAppearance

The text appearance for the week day abbreviation in the calendar header.

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

This corresponds to the global attribute resource symbol weekDayTextAppearance.

Related methods:

android:weekNumberColor

This is deprecated.
The color for the week numbers.

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

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

This corresponds to the global attribute resource symbol weekNumberColor.

Related methods:

android:weekSeparatorLineColor

This is deprecated.
The color for the separator line between weeks.

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

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

This corresponds to the global attribute resource symbol weekSeparatorLineColor.

Related methods:

Public constructors

CalendarView

Added in API level 11
CalendarView (Context context)

Parameters
context Context

CalendarView

Added in API level 11
CalendarView (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

CalendarView

Added in API level 11
CalendarView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

CalendarView

Added in API level 21
CalendarView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getDate

Added in API level 11
long getDate ()

Gets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Returns
long The selected date.

getDateTextAppearance

Added in API level 16
int getDateTextAppearance ()

Gets the text appearance for the calendar dates.

Related XML Attributes:

Returns
int The text appearance resource id.

getFirstDayOfWeek

Added in API level 11
int getFirstDayOfWeek ()

Gets the first day of week.

Related XML Attributes:

Returns
int The first day of the week conforming to the CalendarView APIs.

See also:

getFocusedMonthDateColor

Added in API level 16
int getFocusedMonthDateColor ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the color for the dates in the focused month.

Related XML Attributes:

Returns
int The focused month date color.

getMaxDate

Added in API level 11
long getMaxDate ()

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

Note: The default maximal date is 01/01/2100.

Related XML Attributes:

Returns
long The maximal supported date.

getMinDate

Added in API level 11
long getMinDate ()

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

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

Related XML Attributes:

Returns
long The minimal supported date.

getSelectedDateVerticalBar

Added in API level 16
Drawable getSelectedDateVerticalBar ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the drawable for the vertical bar shown at the beginning and at the end of the selected date.

Returns
Drawable The vertical bar drawable.

getSelectedWeekBackgroundColor

Added in API level 16
int getSelectedWeekBackgroundColor ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the background color for the selected week.

Related XML Attributes:

Returns
int The week background color.

getShowWeekNumber

Added in API level 11
boolean getShowWeekNumber ()

This method was deprecated in API level 24.
No longer used by Material-style CalendarView.

Gets whether to show the week number.

Related XML Attributes:

Returns
boolean True if showing the week number.

getShownWeekCount

Added in API level 16
int getShownWeekCount ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the number of weeks to be shown.

Related XML Attributes:

Returns
int The shown week count.

getUnfocusedMonthDateColor

Added in API level 16
int getUnfocusedMonthDateColor ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the color for the dates in a not focused month.

Related XML Attributes:

Returns
int A not focused month date color.

getWeekDayTextAppearance

Added in API level 16
int getWeekDayTextAppearance ()

Gets the text appearance for the week day abbreviation of the calendar header.

Related XML Attributes:

Returns
int The text appearance resource id.

getWeekNumberColor

Added in API level 16
int getWeekNumberColor ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the color for the week numbers.

Related XML Attributes:

Returns
int The week number color.

getWeekSeparatorLineColor

Added in API level 16
int getWeekSeparatorLineColor ()

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Gets the color for the separator line between weeks.

Related XML Attributes:

Returns
int The week separator color.

setDate

Added in API level 11
void setDate (long date, 
                boolean animate, 
                boolean center)

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
date long: The date.
animate boolean: Whether to animate the scroll to the current date.
center boolean: Whether to center the current date even if it is already visible.
Throws
IllegalArgumentException of the provided date is before the minimal or after the maximal date.

See also:

setDate

Added in API level 11
void setDate (long date)

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
date long: The selected date.
Throws
IllegalArgumentException of the provided date is before the minimal or after the maximal date.

See also:

setDateTextAppearance

Added in API level 16
void setDateTextAppearance (int resourceId)

Sets the text appearance for the calendar dates.

Related XML Attributes:

Parameters
resourceId int: The text appearance resource id.

setFirstDayOfWeek

Added in API level 11
void setFirstDayOfWeek (int firstDayOfWeek)

Sets the first day of week.

Related XML Attributes:

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

See also:

setFocusedMonthDateColor

Added in API level 16
void setFocusedMonthDateColor (int color)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the color for the dates of the focused month.

Related XML Attributes:

Parameters
color int: The focused month date color.

setMaxDate

Added in API level 11
void setMaxDate (long maxDate)

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

Related XML Attributes:

Parameters
maxDate long: The maximal supported date.

setMinDate

Added in API level 11
void setMinDate (long minDate)

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

Related XML Attributes:

Parameters
minDate long: The minimal supported date.

setOnDateChangeListener

Added in API level 11
void setOnDateChangeListener (CalendarView.OnDateChangeListener listener)

Sets the listener to be notified upon selected date change.

Parameters
listener CalendarView.OnDateChangeListener: The listener to be notified.

setSelectedDateVerticalBar

Added in API level 16
void setSelectedDateVerticalBar (int resourceId)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the drawable for the vertical bar shown at the beginning and at the end of the selected date.

Related XML Attributes:

Parameters
resourceId int: The vertical bar drawable resource id.

setSelectedDateVerticalBar

Added in API level 16
void setSelectedDateVerticalBar (Drawable drawable)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the drawable for the vertical bar shown at the beginning and at the end of the selected date.

Related XML Attributes:

Parameters
drawable Drawable: The vertical bar drawable.

setSelectedWeekBackgroundColor

Added in API level 16
void setSelectedWeekBackgroundColor (int color)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the background color for the selected week.

Related XML Attributes:

Parameters
color int: The week background color.

setShowWeekNumber

Added in API level 11
void setShowWeekNumber (boolean showWeekNumber)

This method was deprecated in API level 24.
No longer used by Material-style CalendarView.

Sets whether to show the week number.

Related XML Attributes:

Parameters
showWeekNumber boolean: True to show the week number.

setShownWeekCount

Added in API level 16
void setShownWeekCount (int count)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the number of weeks to be shown.

Related XML Attributes:

Parameters
count int: The shown week count.

setUnfocusedMonthDateColor

Added in API level 16
void setUnfocusedMonthDateColor (int color)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the color for the dates of a not focused month.

Related XML Attributes:

Parameters
color int: A not focused month date color.

setWeekDayTextAppearance

Added in API level 16
void setWeekDayTextAppearance (int resourceId)

Sets the text appearance for the week day abbreviation of the calendar header.

Related XML Attributes:

Parameters
resourceId int: The text appearance resource id.

setWeekNumberColor

Added in API level 16
void setWeekNumberColor (int color)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the color for the week numbers.

Related XML Attributes:

Parameters
color int: The week number color.

setWeekSeparatorLineColor

Added in API level 16
void setWeekSeparatorLineColor (int color)

This method was deprecated in API level 23.
No longer used by Material-style CalendarView.

Sets the color for the separator line between weeks.

Related XML Attributes:

Parameters
color int: The week separator color.

Protected methods

onConfigurationChanged

Added in API level 11
void onConfigurationChanged (Configuration newConfig)

Called when the current configuration of the resources being used by the application have changed. You can use this to decide when to reload resources that can changed based on orientation and other configuration characteristics. You only need to use this if you are not relying on the normal Activity mechanism of recreating the activity instance upon a configuration change.

Parameters
newConfig Configuration: The new resource configuration.

Hooray!