I am using material-calendar for android 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();
but the calender doesn't show the current day on the calender view. so, how to show that?
try this
MaterialCalendarView materialCalView = findViewById(R.id.ID_from_your_xml_code);
materialCalView.setDateSelected(CalendarDay.today(), true);
If you want to set a different color for the current date you have to add a Decorator to your 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));
}
});
Where selector is your custom selector.xml, for example:
<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>
Selector Reference Link: https://github.com/prolificinteractive/material-calendarview/blob/master/docs/CUSTOM_SELECTORS.md
Decorator Reference Link: https://github.com/prolificinteractive/material-calendarview/blob/master/docs/DECORATORS.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With