memfis19 / Cadar

Android solution which represents month and list calendar views.
MIT License
359 stars 48 forks source link

Change the text color of days in month #4

Closed Abdullah-Nasim closed 7 years ago

Abdullah-Nasim commented 7 years ago

How can I change the text color of days in Month Calendar ? Can you please add some of the functions in this library to customize the views.

Regards

memfis19 commented 7 years ago

Hi, you can implement your own view for month day where you can change: text color, background, font style etc. You can do it using setMonthDayLayout method in MonthCalendarConfiguration.Builder, where you should pass your own layout id and MonthDayDecorator implementation where you can customize what you want. Please reference to the source of MonthListCalendarInteractionActivity. Here is example:

MonthCalendarConfiguration.Builder builder = new MonthCalendarConfiguration.Builder(this);
        builder.setMonthDayLayout(R.layout.custom_month_day_layout, new MonthDayDecorator() {
            @Override
            public void onBindDayView(View view, Calendar monthDay, Calendar month, List<Event> eventList, boolean isSelected, boolean isToday) {
                if (!DateUtils.isSameMonth(month, monthDay)) {
                    view.setVisibility(View.GONE);
                    return;
                } else view.setVisibility(View.VISIBLE);
                TextView day = (TextView) view.findViewById(R.id.day_view);
                day.setText(String.valueOf(monthDay.get(Calendar.DAY_OF_MONTH)));
                day.setTextColor(Color.WHITE);

                view.setBackgroundColor(Color.TRANSPARENT);
                if (isToday) view.setBackgroundColor(Color.RED);
                if (isSelected) view.setBackgroundColor(Color.MAGENTA);
            }
        });

where: view - your inflated layout; monthDay - day of month; month - current month; eventList - list of events if you are displaying them or empty (you can use it to show event indicator in day view); isSelected - informs is this day selected; isToday - informs is this day today day. Is it enough for you to customize your own day view?

Abdullah-Nasim commented 7 years ago

Got It! Thank you so much for this awesome work :)

memfis19 commented 7 years ago

FYI you can do the same with week titles for month calendar using setDayWeekTitleLayout. ListCalendarConfiguration.Builder contains similar methods.

memfis19 commented 7 years ago

@Abdullah-Nasim And thank you for your feedback!!! :)