I want to make a Calendar View visible but doesn't editable, only shown to the user with a selected date I tried to set a clickable attribute to false, but it didn't work. and I added a container view then set the clickable attribute to false, but didn't work also
<CalendarView
android:clickable="false"
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I made a workaround, I wrapped it with another view then control the click listener for that view this the only solution that worked for me, and here is my code:
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/FL"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CalendarView android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View android:id="@+id/empty"
android:layout_width="409dp"
android:layout_height="336dp"
android:background="@android:color/transparent"
android:elevation="16dp"
app:layout_constraintBottom_toBottomOf="@id/calendarView"
app:layout_constraintEnd_toEndOf="@id/calendarView"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@id/calendarView"
app:layout_constraintTop_toTopOf="@id/calendarView"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
To Control the listeners :
private fun enableCalendar() {
empty.setOnClickListener(null)
empty.visibility = View.GONE
}
private fun disableCalendar() {
empty.visibility = View.VISIBLE
empty.setOnClickListener {}
}