to top
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 calendar dates. 
android:firstDayOfWeek setFirstDayOfWeek(int) The first day of week according to Calendar
android:focusedMonthDateColor setFocusedMonthDateColor(int) The color for the dates of the focused month. 
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) Drawable for the vertical bar shown at the beginning and at the end of the selected date. 
android:selectedWeekBackgroundColor setSelectedWeekBackgroundColor(int) The background color for the selected week. 
android:showWeekNumber setShowWeekNumber(boolean) Whether do show week numbers. 
android:shownWeekCount setShownWeekCount(int) The number of weeks to be shown. 
android:unfocusedMonthDateColor setUnfocusedMonthDateColor(int) The color for the dates of an unfocused month. 
android:weekDayTextAppearance setWeekDayTextAppearance(int) The text appearance for the week day abbreviation of the calendar header. 
android:weekNumberColor setWeekNumberColor(int) The color for the week numbers. 
android:weekSeparatorLineColor setWeekSeparatorLineColor(int) The color for the separator line between weeks. 
[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 defStyle)
Public Methods
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()
Gets the color for the dates in the focused month.
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()
Gets the drawable for the vertical bar shown at the beginning and at the end of the selected date.
int getSelectedWeekBackgroundColor()
Gets the background color for the selected week.
boolean getShowWeekNumber()
Gets whether to show the week number.
int getShownWeekCount()
Gets the number of weeks to be shown.
int getUnfocusedMonthDateColor()
Gets the color for the dates in a not focused month.
int getWeekDayTextAppearance()
Gets the text appearance for the week day abbreviation of the calendar header.
int getWeekNumberColor()
Gets the color for the week numbers.
int getWeekSeparatorLineColor()
Gets the color for the separator line between weeks.
boolean isEnabled()
Returns the enabled status for this view.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
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 setEnabled(boolean enabled)
Set the enabled state of this view.
void setFirstDayOfWeek(int firstDayOfWeek)
Sets the first day of week.
void setFocusedMonthDateColor(int color)
Sets the color for the dates of the focused month.
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)
Sets the drawable for the vertical bar shown at the beginning and at the end of the selected date.
void setSelectedDateVerticalBar(int resourceId)
Sets the drawable for the vertical bar shown at the beginning and at the end of the selected date.
void setSelectedWeekBackgroundColor(int color)
Sets the background color for the selected week.
void setShowWeekNumber(boolean showWeekNumber)
Sets whether to show the week number.
void setShownWeekCount(int count)
Sets the number of weeks to be shown.
void setUnfocusedMonthDateColor(int color)
Sets the color for the dates of a not focused month.
void setWeekDayTextAppearance(int resourceId)
Sets the text appearance for the week day abbreviation of the calendar header.
void setWeekNumberColor(int color)
Sets the color for the week numbers.
void setWeekSeparatorLineColor(int color)
Sets the color for the separator line between weeks.
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.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android:dateTextAppearance

The text appearance for the calendar dates.

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

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

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

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

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

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

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

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

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

public CalendarView (Context context, AttributeSet attrs)

Added in API level 11

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

Added in API level 11

Public Methods

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
  • The selected date.

public int getDateTextAppearance ()

Added in API level 16

Gets the text appearance for the calendar dates.

Related XML Attributes
Returns
  • The text appearance resource id.

public int getFirstDayOfWeek ()

Added in API level 11

Gets the first day of week.

Related XML Attributes
Returns
  • The first day of the week conforming to the CalendarView APIs.

public int getFocusedMonthDateColor ()

Added in API level 16

Gets the color for the dates in the focused month.

Related XML Attributes
Returns
  • 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
  • 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
  • The minimal supported date.

public Drawable getSelectedDateVerticalBar ()

Added in API level 16

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

Returns
  • The vertical bar drawable.

public int getSelectedWeekBackgroundColor ()

Added in API level 16

Gets the background color for the selected week.

Related XML Attributes
Returns
  • The week background color.

public boolean getShowWeekNumber ()

Added in API level 11

Gets whether to show the week number.

Related XML Attributes
Returns
  • True if showing the week number.

public int getShownWeekCount ()

Added in API level 16

Gets the number of weeks to be shown.

Related XML Attributes
Returns
  • The shown week count.

public int getUnfocusedMonthDateColor ()

Added in API level 16

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

Related XML Attributes
Returns
  • 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
  • The text appearance resource id.

public int getWeekNumberColor ()

Added in API level 16

Gets the color for the week numbers.

Related XML Attributes
Returns
  • The week number color.

public int getWeekSeparatorLineColor ()

Added in API level 16

Gets the color for the separator line between weeks.

Related XML Attributes
Returns
  • The week separator color.

public boolean isEnabled ()

Added in API level 11

Returns the enabled status for this view. The interpretation of the enabled state varies by subclass.

Returns
  • True if this view is enabled, false otherwise.

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Added in API level 14

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Added in API level 14

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

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 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 The date.
animate Whether to animate the scroll to the current date.
center 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 The text appearance resource id.

public void setEnabled (boolean enabled)

Added in API level 11

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

Parameters
enabled True if this view is enabled, false otherwise.

public void setFirstDayOfWeek (int firstDayOfWeek)

Added in API level 11

Sets the first day of week.

Related XML Attributes
Parameters
firstDayOfWeek The first day of the week conforming to the CalendarView APIs.

public void setFocusedMonthDateColor (int color)

Added in API level 16

Sets the color for the dates of the focused month.

Related XML Attributes
Parameters
color 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 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 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 The listener to be notified.

public void setSelectedDateVerticalBar (Drawable drawable)

Added in API level 16

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

Related XML Attributes
Parameters
drawable The vertical bar drawable.

public void setSelectedDateVerticalBar (int resourceId)

Added in API level 16

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

Related XML Attributes
Parameters
resourceId The vertical bar drawable resource id.

public void setSelectedWeekBackgroundColor (int color)

Added in API level 16

Sets the background color for the selected week.

Related XML Attributes
Parameters
color 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 True to show the week number.

public void setShownWeekCount (int count)

Added in API level 16

Sets the number of weeks to be shown.

Related XML Attributes
Parameters
count The shown week count.

public void setUnfocusedMonthDateColor (int color)

Added in API level 16

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

Related XML Attributes
Parameters
color 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 The text appearance resource id.

public void setWeekNumberColor (int color)

Added in API level 16

Sets the color for the week numbers.

Related XML Attributes
Parameters
color The week number color.

public void setWeekSeparatorLineColor (int color)

Added in API level 16

Sets the color for the separator line between weeks.

Related XML Attributes
Parameters
color 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 characterstics. 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 The new resource configuration.