prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.92k stars 1.32k forks source link

How to change color DotSpan with selected day #913

Open CarotUnima opened 5 years ago

CarotUnima commented 5 years ago

I want change color DotSpan when I selected day

I want look like:

screen shot 2018-12-13 at 3 52 54 pm

But ...

screen shot 2018-12-13 at 3 44 22 pm

hkawii commented 5 years ago

I had that issue too and it is solve thanks to DayViewDecorator


public class EventDecorator implements DayViewDecorator {

    private final  ArrayList<CalendarDay> dates;
    private final Context context;

    public EventDecorator(Context context, ArrayList<CalendarDay> dates) {
        this.dates = dates;
        this.context = context;
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return dates.contains(day);
    }

    @Override
    public void decorate(DayViewFacade view) {
        Drawable drawable = ContextCompat.getDrawable(context,R.drawable.calcircleselector);
        assert drawable != null;
        view.setBackgroundDrawable(drawable);
    }
}

Just set "calcircleselector" drawable with the desired colors & shape

You can set multiple dayViewDecorators to the calendar, each one will represent a set of dates with a custom color

EventDecorator eventDecorator = new EventDecorator(getContext(), calDaysArr);
        binding.calendarView.addDecorator(eventDecorator);
CarotUnima commented 5 years ago

I had that issue too and it is solve thanks to DayViewDecorator


public class EventDecorator implements DayViewDecorator {

    private final  ArrayList<CalendarDay> dates;
    private final Context context;

    public EventDecorator(Context context, ArrayList<CalendarDay> dates) {
        this.dates = dates;
        this.context = context;
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return dates.contains(day);
    }

    @Override
    public void decorate(DayViewFacade view) {
        Drawable drawable = ContextCompat.getDrawable(context,R.drawable.calcircleselector);
        assert drawable != null;
        view.setBackgroundDrawable(drawable);
    }
}

Just set "calcircleselector" drawable with the desired colors & shape

You can set multiple dayViewDecorators to the calendar, each one will represent a set of dates with a custom color

EventDecorator eventDecorator = new EventDecorator(getContext(), calDaysArr);
        binding.calendarView.addDecorator(eventDecorator);

You can show me "calcircleselector.xml" . please

hkawii commented 5 years ago

I had that issue too and it is solve thanks to DayViewDecorator


public class EventDecorator implements DayViewDecorator {

    private final  ArrayList<CalendarDay> dates;
    private final Context context;

    public EventDecorator(Context context, ArrayList<CalendarDay> dates) {
        this.dates = dates;
        this.context = context;
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return dates.contains(day);
    }

    @Override
    public void decorate(DayViewFacade view) {
        Drawable drawable = ContextCompat.getDrawable(context,R.drawable.calcircleselector);
        assert drawable != null;
        view.setBackgroundDrawable(drawable);
    }
}

Just set "calcircleselector" drawable with the desired colors & shape You can set multiple dayViewDecorators to the calendar, each one will represent a set of dates with a custom color

EventDecorator eventDecorator = new EventDecorator(getContext(), calDaysArr);
        binding.calendarView.addDecorator(eventDecorator);

You can show me "calcircleselector.xml" . please

Sure, it is just a simple oval shape, and certainly customise it according to your needs and the dot color can be edited within the decorate function too view.addSpan(new DotSpan(Color.BLUE));

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid
        android:color="@color/color_blue"/>
</shape>
Venkatesh-TSS commented 4 years ago

how to set the default appointment color blue and when i select the date the blue will be changed into white.