Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
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 .

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 .

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 .

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)

public CalendarView ( Context context, AttributeSet attrs)

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

Public Methods

public long getDate ()

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

Returns
  • The selected date.

public int getDateTextAppearance ()

Gets the text appearance for the calendar dates.

Related XML Attributes
Returns
  • The text appearance resource id.

public int getFirstDayOfWeek ()

Gets the first day of week.

Related XML Attributes
Returns

public int getFocusedMonthDateColor ()

Gets the color for the dates in the focused month.

Related XML Attributes
Returns
  • The focused month date color.

public 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
  • The maximal supported date.

public 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
  • The minimal supported date.

public Drawable getSelectedDateVerticalBar ()

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

Gets the background color for the selected week.

Returns
  • The week background color.

public boolean getShowWeekNumber ()

Gets whether to show the week number.

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

public int getShownWeekCount ()

Gets the number of weeks to be shown.

Related XML Attributes
Returns
  • The shown week count.

public int getUnfocusedMonthDateColor ()

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

Related XML Attributes
Returns
  • A not focused month date color.

public int getWeekDayTextAppearance ()

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

Gets the color for the week numbers.

Related XML Attributes
Returns
  • The week number color.

public int getWeekSeparatorLineColor ()

Gets the color for the separator line between weeks.

Related XML Attributes
Returns
  • The week separator color.

public boolean isEnabled ()

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)

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)

Parameters
info The instance to initialize.

public void setDate (long date)

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)

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)

Sets the text appearance for the calendar dates.

Related XML Attributes
Parameters
resourceId The text appearance resource id.

public void setEnabled (boolean enabled)

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)

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)

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)

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)

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)

Sets the listener to be notified upon selected date change.

Parameters
listener The listener to be notified.

public void setSelectedDateVerticalBar ( Drawable drawable)

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)

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)

Sets the background color for the selected week.

Parameters
color The week background color.

public void setShowWeekNumber (boolean showWeekNumber)

Sets whether to show the week number.

Related XML Attributes
Parameters
showWeekNumber True to show the week number.

public void setShownWeekCount (int count)

Sets the number of weeks to be shown.

Related XML Attributes
Parameters
count The shown week count.

public void setUnfocusedMonthDateColor (int color)

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)

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)

Sets the color for the week numbers.

Related XML Attributes
Parameters
color The week number color.

public void setWeekSeparatorLineColor (int color)

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)

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.