如何在 android 日历视图中 select 多个日期

How to select multiple dates on android calender view

    val calendar: Calendar = Calendar.getInstance()
    calendar.set(2022, 5, 10)
    val dateSelected = calendar.timeInMillis

    val calender2 = Calendar.getInstance()
    calender2.set(2022, 5, 11)
    val dateSelected2 = calender2.timeInMillis
    
    binding?.calenderView?.setDate(dateSelected, true, true)
    binding?.calenderView?.setDate(dateSelected2, true, true)

我试过 select 如上所示的两个日期,但它不起作用?有帮助吗?

如果您只想 select 日期范围,请尝试 material 日期选择器 material date picker doc

 MaterialDatePicker.Builder.dateRangePicker().build().show(supportFragmentManager, "")
            val dateRangePicker =
            MaterialDatePicker.Builder
                .dateRangePicker()
                .setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar)
                .setTitleText("Title")
                .setSelection(
                    Pair(
                        MaterialDatePicker.thisMonthInUtcMilliseconds(),
                        MaterialDatePicker.todayInUtcMilliseconds()
                    )
                )
                .build()

        dateRangePicker.show(childFragmentManager, "tag")
        dateRangePicker.addOnPositiveButtonClickListener {
            println(it.first)
            println(it.second)

        }