CompactCalendarView是提供个月滚动一个简单的日历视图。它是基于Java的Date和Calendar类。它提供了一个简单的API来查询日期和监听特定事件。例如,当日历已滚动至一个新的月份或一天已被选中。仍在积极发展。
请提出的要求的问题,使编写任何代码之前的讨论可以,即使你打算提出一个拉请求。
该库还支持开/带或不带动画关闭。
有可能通过几个属性来改变视图的外观。这包括背景颜色,文本颜色,当前日的TEXTSIZE颜色和该月的第一天的颜色。
<com.github.sundeepk.compactcalendarview.CompactCalendarView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/compactcalendar_view"
android:layout_width="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_height="250dp"
app:compactCalendarTargetHeight="250dp"
app:compactCalendarTextSize="12sp"
app:compactCalendarBackgroundColor="#ffe95451"
app:compactCalendarTextColor="#fff"
app:compactCalendarCurrentSelectedDayBackgroundColor="#E57373"
app:compactCalendarCurrentDayBackgroundColor="#B71C1C"
app:compactCalendarMultiEventIndicatorColor="#fff"
/>
请参阅完整的例子示例应用程序。
// ...代码不再赘述
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
// Add event 1 on Sun, 07 Jun 2015 18:20:51 GMT
Event ev1 new Event(Color.GREEN, 1433701251000L, "Some extra data that I want to store.");
compactCalendar.addEvent(ev1);
// Added event 2 GMT: Sun, 07 Jun 2015 19:10:51 GMT
Event ev2 = new Event(Color.GREEN, 1433704251000L);
compactCalendar.addEvent(ev2);
// Query for events on Sun, 07 Jun 2015 GMT.
// Time is not relevant when querying for events, since events are returned by day.
// So you can pass in any arbitary DateTime and you will receive all events for that day.
List<Event> events = compactCalendar.getEvents(1433701251000L); // can also take a Date object
// events has size 2 with the 2 events inserted previously
Log.d(TAG, "Events: " + events);
// define a listener to receive callbacks when certain events happen.
compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
List<Event> events = compactCalendarView.getEvents(dateClicked);
Log.d(TAG, "Day was clicked: " + dateClicked + " with events " + events);
}
@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
Log.d(TAG, "Month was scrolled to: " + firstDayOfNewMonth);
}
});
}
可以使用的样式预设修改的指标,下面是一个例子,但是其他一些组合也是可能的:
需要注意的是日历没有试图去重复了相同的确切日期时间事件。这是东西,你必须处理你的自我,如果它是你的使用情况非常重要。
这是可能的设置位置,这样平日列名由日历自动设置。
CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
compactCalendarView.setLocale(Locale.CHINESE);
compactCalendarView.setUseThreeLetterAbbreviation(true);
dependencies {
compile 'com.github.sundeepk:compact-calendar-view:1.9.5'
}