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 a theme attribute in the form "?[package:]type/name".

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

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.

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

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 a theme attribute in the form "?[package:]type/name".

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

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

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

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

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

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 a theme attribute in the form "?[package:]type/name".

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

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 a theme attribute in the form "?[package:]type/name".

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

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 a theme attribute in the form "?[package:]type/name".

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

Inherited XML attributes

Inherited constants

Inherited fields

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 TimeZone#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 TimeZone#getDefault() time zone.

long getMinDate()

Gets the minimal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in TimeZone#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 TimeZone#getDefault() time zone.

void setDate(long date)

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in TimeZone#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 TimeZone#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 TimeZone#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

XML attributes

android:dateTextAppearance

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

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

Related methods:

android:firstDayOfWeek

The first day of week according to Calendar.

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

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 a theme attribute in the form "?[package:]type/name".

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

Related methods:

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;

Related methods:

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;

Related methods:

android:selectedDateVerticalBar

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

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

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 a theme attribute in the form "?[package:]type/name".

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

Related methods:

android:showWeekNumber

This is deprecated.
Whether do show week numbers.

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

Related methods:

android:shownWeekCount

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

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

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 a theme attribute in the form "?[package:]type/name".

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

Related methods:

android:weekDayTextAppearance

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

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

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 a theme attribute in the form "?[package:]type/name".

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

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 a theme attribute in the form "?[package:]type/name".

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

Related methods:

Public constructors

CalendarView

Added in API level 11
public CalendarView (Context context)

Parameters
context Context: This value cannot be null.

CalendarView

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

Parameters
context Context: This value cannot be null.

attrs AttributeSet: This value may be null.

CalendarView

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

Parameters
context Context: This value cannot be null.

attrs AttributeSet: This value may be null.

defStyleAttr int

CalendarView

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

Parameters
context Context: This value cannot be null.

attrs AttributeSet: This value may be null.

defStyleAttr int

defStyleRes int

Public methods

getAccessibilityClassName

Added in API level 23
public 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
public long getDate ()

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

Returns
long The selected date.

getDateTextAppearance

Added in API level 16
public 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
public int getFirstDayOfWeek ()

Gets the first day of week.

Related XML Attributes:

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

getFocusedMonthDateColor

Added in API level 16
Deprecated in API level 23
public 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
public long getMaxDate ()

Gets the maximal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in TimeZone#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
public long getMinDate ()

Gets the minimal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in TimeZone#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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
Deprecated in API level 24
public 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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
public 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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
public void setDate (long date, 
                boolean animate, 
                boolean center)

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in TimeZone#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.

setDate

Added in API level 11
public void setDate (long date)

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

Parameters
date long: The selected date.

Throws
IllegalArgumentException of the provided date is before the minimal or after the maximal date.

setDateTextAppearance

Added in API level 16
public 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
public 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.

setFocusedMonthDateColor

Added in API level 16
Deprecated in API level 23
public 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
public void setMaxDate (long maxDate)

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

Related XML Attributes:

Parameters
maxDate long: The maximal supported date.

setMinDate

Added in API level 11
public void setMinDate (long minDate)

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

Related XML Attributes:

Parameters
minDate long: The minimal supported date.

setOnDateChangeListener

Added in API level 11
public 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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
Deprecated in API level 24
public 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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
public 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
Deprecated in API level 23
public 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
Deprecated in API level 23
public 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
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 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.