Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification: Can I able to show the events of a particular day using this calendar #1075

Open
nihp opened this issue Nov 5, 2020 · 11 comments

Comments

@nihp
Copy link

nihp commented Nov 5, 2020

Need to show the calendar events. Can I able to show the events using material calendarview

@XanderZehcnas
Copy link

You can mark the days with events with a specific decorator. See the documentation about daydecorators.

@nihp
Copy link
Author

nihp commented Nov 16, 2020

@XanderZehcnas Can you let me know shall I able to show the dates and header of the calendar in a different color and custom style for this calendar view

@XanderZehcnas
Copy link

You can highlight a day with a color dot (This is what I have implemented) or you can create your own decorator (or so it seems)
You can for example use a dot Decorator like this:

class CalendarEventDecorator(private val color: Int, private val dates: Collection<CalendarDay?>?): DayViewDecorator {

override fun shouldDecorate(day: CalendarDay): Boolean {
    return dates!!.contains(day)
}

override fun decorate(view: DayViewFacade) {
    view.addSpan(DotSpan(5F, color))
}

}

This decorator can then be applied to a set of dates. In my case I observe a list of CalendarDay (The class used within this library) to incorporate the decorators:

viewModel.reservedDates.observe(viewLifecycleOwner, Observer {reservedDates->
if (reservedDates != null) {
calendarView.removeDecorators()
calendarView.addDecorator(
CalendarEventDecorator(ContextCompat.getColor(requireContext(),R.color.primaryColor),reservedDates.filter{ it.isInRange(calendarView.minimumDate,calendarView.maximumDate) }))
} else {
calendarView.removeDecorators()
}
})

@nihp
Copy link
Author

nihp commented Nov 17, 2020

@XanderZehcnas Thanks for your detailed explanation.

Can I able to set background for this https://i.stack.imgur.com/Z16zO.png. Now I have the header and calendar in a same color. But I need to show the calendar background header as blue and calendar dates background as white

@XanderZehcnas
Copy link

XanderZehcnas commented Nov 17, 2020 via email

@nihp
Copy link
Author

nihp commented Nov 17, 2020

@XanderZehcnas Thanks for reply.

My Calendar is inside a LinearLayout. How can I add two view for this?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<!-- Add TextView to display the date -->
<!-- Add CalenderView to display the Calender -->
    <com.prolificinteractive.materialcalendarview.MaterialCalendarView
        android:id="@+id/calendar_view"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_marginTop="50dp"
        android:layout_gravity="center"
        app:mcv_selectionColor="#00ADEC"
        android:background="@drawable/calendar_background"
        app:mcv_showOtherDates="defaults"/>
</LinearLayout>

@XanderZehcnas
Copy link

XanderZehcnas commented Nov 17, 2020 via email

@nihp
Copy link
Author

nihp commented Nov 17, 2020

Okay thanks I will add the above inside the Constraint Layout. Will check.

@nihp
Copy link
Author

nihp commented Nov 18, 2020

It shows an empty screen. Why the layout_height is 0dp? Can you please elaborate it?

If I make the layout_height to any value it will show the calendar with the background which I set for the entire one @drawable/round_back_shape.

@nihp
Copy link
Author

nihp commented Nov 18, 2020

I need like the below image.
I think the splitting of views not works.
Screenshot 2020-11-18 at 1 59 41 PM

@rafsanjani
Copy link

@nihp Just put the calendar inside a MaterialCardView and set the cornerRadius of the cardview to something like 15dp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants