使用代码
override fun lazyInit() {
viewBinding.flStartDay.click { viewBinding.calendarView.pickType = PickType.RANGE_START }
viewBinding.flEndDay.click { viewBinding.calendarView.pickType = PickType.RANGE_END }
val calendarView = viewBinding.calendarView
calendarView.typeface = ResourcesCompat.getFont(mContext, R.font.roboto_medium)
calendarView.calendarType = CalendarType.CIVIL
calendarView.pickType = PickType.SINGLE
calendarView.flingOrientation = PrimeCalendarView.FlingOrientation.HORIZONTAL
calendarView.locale = Locale.getDefault()
calendarView.animateSelection = false
calendarView.pickedDayLabelTextColor = Color.WHITE
calendarView.firstDayOfWeek = Calendar.SUNDAY
calendarView.todayLabelTextColor = Color.parseColor("#c62430")
calendarView.dayLabelTextColor = Color.parseColor("#333333")
calendarView.disabledDayLabelTextColor = Color.parseColor("#C5C5C5")
calendarView.pickedDayBackgroundColor = Color.parseColor("#c62430")
calendarView.weekLabelTextColor = Color.parseColor("#333333")
calendarView.monthLabelTextColor = Color.parseColor("#333333")
calendarView.dividerColor = Color.TRANSPARENT
calendarView.dividerInsetBottom = 0
calendarView.dividerInsetTop = 0
calendarView.dividerInsetLeft = 0
calendarView.dividerInsetRight = 0
calendarView.dayLabelTextSize = 14.dp2px()
calendarView.weekLabelTextSize = 12.dp2px()
calendarView.monthLabelTextSize = 12.dp2px()
calendarView.minDateCalendar = CalendarFactory.newInstance(CalendarType.CIVIL).also { it[Calendar.MONTH] -= 12 }
calendarView.maxDateCalendar = CalendarFactory.newInstance(CalendarType.CIVIL)
calendarView.onDayPickedListener = OnDayPickedListener { _, _, startDay, endDay, _ ->
if (startDay != null) viewBinding.tvStartDay.text = "${startDay.year}-${startDay.month + 1}-${startDay.dayOfMonth}"
if (endDay != null) viewBinding.tvEndDay.text = "${endDay.year}-${endDay.month + 1}-${endDay.dayOfMonth}"
}
}
效果图