Android Week View is an android library to display calendars within the app
Android Week View
Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
Features
- Week view calendar
- Day view calendar
- Custom styling
- Horizontal and vertical scrolling
- Infinite horizontal scrolling
- Live preview of custom styling in xml preview window
Usage
- Import the library into your project.
-
Grab via maven
<dependency> <groupId>com.github.alamkanak</groupId> <artifactId>android-week-view</artifactId> <version>1.2.6</version> <type>aar</type> </dependency>
-
Grab via gradle
compile 'com.github.alamkanak:android-week-view:1.2.6'
-
Add WeekView in your xml layout.
<com.alamkanak.weekview.WeekView android:id="@+id/weekView" android:layout_width="match_parent" android:layout_height="match_parent" app:eventTextColor="@android:color/white" app:textSize="12sp" app:hourHeight="60dp" app:headerColumnPadding="8dp" app:headerColumnTextColor="#8f000000" app:headerRowPadding="12dp" app:columnGap="8dp" app:noOfVisibleDays="3" app:headerRowBackgroundColor="#ffefefef" app:dayBackgroundColor="#05000000" app:todayBackgroundColor="#1848adff" app:headerColumnBackground="#ffffffff"/>
-
Write the following code in your java file.
// Get a reference for the week view in the layout. mWeekView = (WeekView) findViewById(R.id.weekView); // Set an action when any event is clicked. mWeekView.setOnEventClickListener(mEventClickListener); // The week view has infinite scrolling horizontally. We have to provide the events of a // month every time the month changes on the week view. mWeekView.setMonthChangeListener(mMonthChangeListener); // Set long press listener for events. mWeekView.setEventLongPressListener(mEventLongPressListener);
-
Implement
WeekView.MonthChangeListener
,WeekView.EventClickListener
,WeekView.EventLongPressListener
according to your need. -
Provide the events for the
WeekView
inWeekView.MonthChangeListener.onMonthChange()
callback. Please remember that the calendar pre-loads events of three consecutive months to enable lag-free scrolling.MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() { @Override public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List<WeekViewEvent> events = getEvents(newYear, newMonth); return events; } };