0

I wants to highlight multi-selected dates like absent(red color), present(green color) and holidays(blue color). I show many sites or github or stackoverflow answer but not find perfect solution. Also set minimum and maximum dates to show calendar.

My question is like this link example but no solution found.

Please help me to find perfect solution.

3 Answers3

0

Follow this link to get the library mCalendarView

1.Use 3rd party library McalenderView.

2.Add to your gradle:-

'sun.bob:mcalendarview:1.0.0'

Try this code:-

3.Some code:-

calendarView = ((MCalendarView) view.findViewById(R.id.calendar_exp));

    ArrayList<DateData> dates=new ArrayList<>();
    dates.add(new DateData(2018,04,26));
    dates.add(new DateData(2018,04,27));

    for(int i=0;i<dates.size();i++) {
        calendarView.markDate(dates.get(i).getYear(),dates.get(i).getMonth(),dates.get(i).getDay());//mark multiple dates with this code.
    }


    Log.d("marked dates:-",""+calendarView.getMarkedDates());//get all marked dates.
Naveed Abbas
  • 220
  • 3
  • 10
0

Try out with these library :

dependencies {
implemantation 'com.savvi.datepicker:rangepicker:1.3.0'
}

Inside layout :

 <com.savvi.rangedatepicker.CalendarPickerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/calendar_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarStyle="outsideOverlay"
    android:clipToPadding="false"
    app:tsquare_orientation_horizontal="false"
    app:tsquare_dividerColor="@color/transparent"
    app:tsquare_headerTextColor="@color/custom_header_text"
    /> 

Initialize it in Java Class

   calendar.init(lastYear.getTime(), nextYear.getTime()) //
            .inMode(CalendarPickerView.SelectionMode.RANGE)
            .withSelectedDate(new Date())
 // deactivates given dates, non selectable
            .withDeactivateDates(list)
 // highlight dates in red color, mean they are aleady used.
            .withHighlightedDates(arrayList)
// add subtitles to the dates pass a arrayList of SubTitle objects with date and text
            .withSubtitles(getSubtitle())

More : https://github.com/savvisingh/DateRangePicker

haresh
  • 1,424
  • 2
  • 12
  • 18
0

change color by condition

if (res.type == "Type") {
calendarView.markDate(DateData(dateAsyear, dateAsMonth, dateAsDay).setMarkStyle(MarkStyle(MarkStyle.BACKGROUND, (ContextCompat.getColor(requireContext(),R.color.YOURCOLOR)))))
}
Rafel C.F
  • 179
  • 1
  • 10