0

i want to change some days background color to other color but it doesnt work that i expect


        val calendarView: CalendarView = attendanceInquiryBinding.attendanceCalendarView

        val calendar = Calendar.getInstance()
        calendar.set(Calendar.YEAR, 2024)
        calendar.set(Calendar.MONTH, Calendar.FEBRUARY)
        calendar.set(Calendar.DAY_OF_MONTH, 15)

        val greenBackgroundDrawable = ColorDrawable(resources.getColor(R.color.greencal))

        val eventDay = EventDay(calendar, greenBackgroundDrawable)

        val eventDaysList = mutableListOf<EventDay>()
        eventDaysList.add(eventDay)

        calendarView.setEvents(eventDaysList)

        val list = listOf(
            CalendarDay(calendar).apply {
               // labelColor = [color resource]
                backgroundResource = R.drawable.calendar_selected

            }
        )

        calendarView.setCalendarDays(list)

thats my code but it has empty space like this enter image description here what can i do to fill up the color of the background

1 Answer 1

1

Please check sample module in Material-Calendar-View library. There are an examples where calendar background is same as day background and selected is marked with an image not the background.

If howeather you need remove margins between week rows when days are selected please modify calendar_view_picker_day.xml in such way:

Set <LinearLayout height same as child textView so android:layout_height="@dimen/day_label_size_events_disabled". Set <LinearLayout android:padding="0dp"

All modifications:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/day_label_size_events_disabled"
    android:background="@drawable/day_picker_item_background"
    android:padding="0dp"
    android:orientation="vertical">
    <TextView ....

Not the answer you're looking for? Browse other questions tagged or ask your own question.