Android APIs
public class

CalendarView

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

Class Overview

This class is a calendar widget for displaying and selecting dates. The range of dates supported by this calendar is configurable. A user can select a date by taping on it and can scroll and 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
Attribute Name Related Method Description
android:dateTextAppearance setDateTextAppearance(int) The text appearance for the day numbers in the calendar grid. 
android:firstDayOfWeek setFirstDayOfWeek(int) The first day of week according to Calendar
android:focusedMonthDateColor setFocusedMonthDateColor(int) 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 setMaxDate(long) The minimal date shown by this calendar view in mm/dd/yyyy format. 
android:minDate setMinDate(long) The minimal date shown by this calendar view in mm/dd/yyyy format. 
android:selectedDateVerticalBar setSelectedDateVerticalBar(int) 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 setSelectedWeekBackgroundColor(int) 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 setShowWeekNumber(boolean) 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 setShownWeekCount(int) 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 setUnfocusedMonthDateColor(int) 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 setWeekDayTextAppearance(int) The text appearance for the week day abbreviation in the calendar header. 
android:weekNumberColor setWeekNumberColor(int) 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 setWeekSeparatorLineColor(int) 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. 

[Expand]
Inherited XML Attributes
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
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()
Gets whether to show the week number.
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)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
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 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(Drawable drawable)
This method was deprecated in API level 23. No longer used by Material-style CalendarView.
void setSelectedDateVerticalBar(int resourceId)
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)
Sets whether to show the week number.
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.
[Expand]
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.

android:maxDate

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

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.

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.

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.

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.

Public Constructors

public CalendarView (Context context)

Added in API level 11

Parameters
context Context

public CalendarView (Context context, AttributeSet attrs)

Added in API level 11

Parameters
context Context
attrs AttributeSet

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

Added in API level 11

Parameters
context Context
attrs AttributeSet
defStyleAttr int

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

Added in API level 21

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public Methods

public CharSequence getAccessibilityClassName ()

Added in API level 23

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

public long getDate ()

Added in API level 11

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

Returns
long The selected date.

public int getDateTextAppearance ()

Added in API level 16

Gets the text appearance for the calendar dates.

Related XML Attributes:

Returns
int The text appearance resource id.

public int getFirstDayOfWeek ()

Added in API level 11

Gets the first day of week.

Related XML Attributes:

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

public int getFocusedMonthDateColor ()

Added in API level 16

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.

public long getMaxDate ()

Added in API level 11

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.

public long getMinDate ()

Added in API level 11

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.

public Drawable getSelectedDateVerticalBar ()

Added in API level 16

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.

public int getSelectedWeekBackgroundColor ()

Added in API level 16

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.

public boolean getShowWeekNumber ()

Added in API level 11

Gets whether to show the week number.

Related XML Attributes:

Returns
boolean True if showing the week number.

public int getShownWeekCount ()

Added in API level 16

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.

public int getUnfocusedMonthDateColor ()

Added in API level 16

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.

public int getWeekDayTextAppearance ()

Added in API level 16

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

Related XML Attributes:

Returns
int The text appearance resource id.

public int getWeekNumberColor ()

Added in API level 16

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.

public int getWeekSeparatorLineColor ()

Added in API level 16

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.

public void setDate (long date)

Added in API level 11

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.

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

Added in API level 11

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.

public void setDateTextAppearance (int resourceId)

Added in API level 16

Sets the text appearance for the calendar dates.

Related XML Attributes:

Parameters
resourceId int: The text appearance resource id.

public void setFirstDayOfWeek (int firstDayOfWeek)

Added in API level 11

Sets the first day of week.

Related XML Attributes:

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

public void setFocusedMonthDateColor (int color)

Added in API level 16

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.

public void setMaxDate (long maxDate)

Added in API level 11

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.

public void setMinDate (long minDate)

Added in API level 11

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.

public void setOnDateChangeListener (CalendarView.OnDateChangeListener listener)

Added in API level 11

Sets the listener to be notified upon selected date change.

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

public void setSelectedDateVerticalBar (Drawable drawable)

Added in API level 16

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.

public void setSelectedDateVerticalBar (int resourceId)

Added in API level 16

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.

public void setSelectedWeekBackgroundColor (int color)

Added in API level 16

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.

public void setShowWeekNumber (boolean showWeekNumber)

Added in API level 11

Sets whether to show the week number.

Related XML Attributes:

Parameters
showWeekNumber boolean: True to show the week number.

public void setShownWeekCount (int count)

Added in API level 16

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.

public void setUnfocusedMonthDateColor (int color)

Added in API level 16

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.

public void setWeekDayTextAppearance (int resourceId)

Added in API level 16

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

Related XML Attributes:

Parameters
resourceId int: The text appearance resource id.

public void setWeekNumberColor (int color)

Added in API level 16

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.

public void setWeekSeparatorLineColor (int color)

Added in API level 16

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

protected void onConfigurationChanged (Configuration newConfig)

Added in API level 11

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.