Reputation: 1522
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?
Upvotes: 4
Views: 9639
Reputation: 111
try this
MaterialCalendarView materialCalView = findViewById(R.id.ID_from_your_xml_code);
materialCalView.setDateSelected(CalendarDay.today(), true);
Upvotes: 6
Reputation: 25
MaterialCalendarView materialCalendarView=(MaterialCalendarView) findViewById (R.id.calendarView);
Calendar calendar = Calendar.getInstance();
materialCalendarView.setDateSelected(calendar.getTime(), true);
I hope this might help you
Upvotes: 1
Reputation: 367
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
Upvotes: 5
Reputation: 760
I am setting firstDayOfWeek as below
mcv = (MaterialCalendarView) findViewById(R.id.calendarView);
mcv.state().edit()
.setFirstDayOfWeek(Calendar.MONDAY)
.commit();
Upvotes: -1