Material-calendarview: how to show current Date

Created on 1 Sep 2016  路  4Comments  路  Source: prolificinteractive/material-calendarview

i wat show current date with different color when i selected other date

Most helpful comment

@abhiwaikar, @yatindeokar

MaterialCalendarView calendarView = (MaterialCalendarView) findViewById(R.id.calendarView);
Calendar calendar = Calendar.getInstance();
calendarView.setDateSelected(calendar.getTime(), true);

All 4 comments

i have same question ...how to show current date

@abhiwaikar, @yatindeokar

MaterialCalendarView calendarView = (MaterialCalendarView) findViewById(R.id.calendarView);
Calendar calendar = Calendar.getInstance();
calendarView.setDateSelected(calendar.getTime(), true);

You can actually do that using a decorator: https://github.com/prolificinteractive/material-calendarview/blob/master/docs/DECORATORS.md.

public class EventDecorator implements DayViewDecorator {

    private final int color;
    private final CalendarDay today;

    public EventDecorator(int color, CalendarDay today) {
        this.color = color;
        this.today = today;
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return day.equalsTo(today);
    }

    @Override
    public void decorate(DayViewFacade view) {
        view.addSpan(new DotSpan(5, color));
    }
}

Once you are able to show today's date highlighted, you might need to improve using https://github.com/prolificinteractive/material-calendarview/blob/master/docs/CUSTOM_SELECTORS.md

@Override
    public boolean shouldDecorate(CalendarDay day) {
        return day.equalsTo(today); // change equalsTo to **equals**

    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

TokyoAndroid picture TokyoAndroid  路  4Comments

marcello-marabita-mblabs picture marcello-marabita-mblabs  路  8Comments

Maragues picture Maragues  路  5Comments

erylljoy24 picture erylljoy24  路  3Comments

chrismabotuwana picture chrismabotuwana  路  4Comments