我正在使用物料日历安卓 https://github.com/prolificinteractive/material-calendarview
materialCalender = (MaterialCalendarView)v.findViewById(R.id.calendarView);
materialCalender.state().edit()
.setFirstDayOfWeek(Calendar.MONDAY)
.setMinimumDate(CalendarDay.from(1900, 1, 1))
.setMaximumDate(CalendarDay.from(2100, 12, 31))
.setCalendarDisplayMode(CalendarMode.MONTHS)
.commit();
但日历未在日历视图中显示当天。 那么,如何表明呢?
答案 0 :(得分:2)
如果要为当前日期设置不同的颜色,则必须将Decorator添加到MaterialCalendarView:
calendarView.addDecorator(new DayViewDecorator() {
@Override
public boolean shouldDecorate(CalendarDay day) {
Calendar cal1 = day.getCalendar();
Calendar cal2 = Calendar.getInstance();
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
&& cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
&& cal1.get(Calendar.DAY_OF_YEAR) ==
cal2.get(Calendar.DAY_OF_YEAR));
}
@Override
public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(ContextCompat.getDrawable(MainActivity.this,R.drawable.selector));
}
});
其中selector是您的自定义selector.xml,例如:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item
android:state_checked="true"
android:drawable="@color/yourColor"
/>
<item
android:state_pressed="true"
android:drawable="@color/yourColor"
/>
<item android:drawable="@android:color/transparent" />
</selector>
选择器参考链接:https://github.com/prolificinteractive/material-calendarview/blob/master/docs/CUSTOM_SELECTORS.md
装饰者参考链接:https://github.com/prolificinteractive/material-calendarview/blob/master/docs/DECORATORS.md
答案 1 :(得分:1)
尝试
MaterialCalendarView materialCalView = findViewById(R.id.ID_from_your_xml_code);
materialCalView.setDateSelected(CalendarDay.today(), true);
答案 2 :(得分:-1)
我正在设置firstDayOfWeek,如下所示
mcv = (MaterialCalendarView) findViewById(R.id.calendarView);
mcv.state().edit()
.setFirstDayOfWeek(Calendar.MONDAY)
.commit();