一款好看的日曆控制元件
阿新 • • 發佈:2018-12-10
android 一款好看的日曆控制元件
1.依賴包
compile 'com.prolificinteractive:material-calendarview:1.4.0'
佈局中的使用:
<com.prolificinteractive.materialcalendarview.MaterialCalendarView android:id="@+id/calendarView" android:layout_width="match_parent" android:layout_height="wrap_content"
3.在JAVA程式碼中的使用:
1.監聽選中的時間
mSettimeTimeMv.setOnDateChangedListener(new OnDateSelectedListener() {
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
CalendarDay selectedDate = mSettimeTimeMv.getSelectedDate();
String data = dateInstance.format(selectedDate.getDate());
//TODO
}
});
2.設定時間範圍
widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
Calendar instance = Calendar.getInstance();
widget.setSelectedDate(instance.getTime());
Calendar instance1 = Calendar.getInstance();
instance1.set(instance1.get(Calendar.YEAR), Calendar.JANUARY, 1);
Calendar instance2 = Calendar.getInstance();
instance2.set(instance2.get(Calendar.YEAR), Calendar.DECEMBER, 31);
widget.state().edit()
.setMinimumDate(instance1.getTime())
.setMaximumDate(instance2.getTime())
.commit();