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

Today's and selected date's text color #1100

Closed RakeshPatil111 closed 3 years ago

RakeshPatil111 commented 3 years ago

How to set text color for today's date and different text color for selected date?

RakeshPatil111 commented 3 years ago

Found solution

aashitshah26 commented 3 years ago

Whats the solution ?

GCancinoH commented 2 years ago

What was the solution, @RakeshPatil111 ?

dungtmagithub commented 1 year ago

What is the solution?

RakeshPatil111 commented 1 year ago

Add custom decorator.

class CalendarDateTodayDecorator(val context: Context) : DayViewDecorator {

  override fun shouldDecorate(day: CalendarDay?): Boolean {
    return day == CalendarDay.today()
  }

  override fun isDecorationDynamic(): Boolean {
    return true
  }

  override fun decorate(view: DayViewFacade?) {
    view?.addSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.red)))
  }
}

Set this decorator,

view.addDecorators(CircularDateSelectionDecorator(requireContext()), calendarDateDecorator)

I needed circle around selected date so created CircularDateSelectionDecorator, you can create other decorators depending upon your need.

class CircularDateSelectionDecorator(context: Context) : DayViewDecorator {

  private val drawable: Drawable = ContextCompat.getDrawable(context, R.drawable.event_calendar_date_selector)!!

  override fun shouldDecorate(day: CalendarDay): Boolean {
    return true
  }

  override fun isDecorationDynamic(): Boolean {
    return false
  }

  override fun decorate(view: DayViewFacade) {
    view.setSelectionDrawable(drawable)
  }

NOTE This solution is a 2 years old, may be will not work now.

dungtmagithub commented 1 year ago

Add custom decorator.

class CalendarDateTodayDecorator(val context: Context) : DayViewDecorator {

  override fun shouldDecorate(day: CalendarDay?): Boolean {
    return day == CalendarDay.today()
  }

  override fun isDecorationDynamic(): Boolean {
    return true
  }

  override fun decorate(view: DayViewFacade?) {
    view?.addSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.red)))
  }
}

Set this decorator,

view.addDecorators(CircularDateSelectionDecorator(requireContext()), calendarDateDecorator)

I needed circle around selected date so created CircularDateSelectionDecorator, you can create other decorators depending upon your need.

class CircularDateSelectionDecorator(context: Context) : DayViewDecorator {

  private val drawable: Drawable = ContextCompat.getDrawable(context, R.drawable.event_calendar_date_selector)!!

  override fun shouldDecorate(day: CalendarDay): Boolean {
    return true
  }

  override fun isDecorationDynamic(): Boolean {
    return false
  }

  override fun decorate(view: DayViewFacade) {
    view.setSelectionDrawable(drawable)
  }

NOTE This solution is a 2 years old, may be will not work now.

Thank you