본문 바로가기
android

[Android] cosmo calendarview - 캘린더뷰 커스텀

by 래끼 2022. 6. 16.
728x90
반응형

 

 

캘린더 뷰 커스텀에 대해 알아보던 중에 cosmo calendarview를 알게되어 한번 사용해보았다!

 

https://github.com/ApplikeySolutions/CosmoCalendar

 

GitHub - ApplikeySolutions/CosmoCalendar: 📅 CosmoCalendar is a fully customizable calendar with a wide variety of features an

📅 CosmoCalendar is a fully customizable calendar with a wide variety of features and displaying modes. - GitHub - ApplikeySolutions/CosmoCalendar: 📅 CosmoCalendar is a fully customizable calendar ...

github.com

 

 

 

 

 

1. 먼저 필요한 module 단위 build.gradle 파일에 cosmo calendarview 를 implementation 해준다

    implementation 'com.github.applikeysolutions:cosmocalendar:1.0.4'

 

 

2. layout파일에 <cosmocalendar> 위젯추가해준다

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.applikeysolutions.cosmocalendar.view.CalendarView
        android:id="@+id/calendar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:connectedDayIconPosition="top"
        app:currentDayIconRes="@drawable/ic_close_gray"
        app:currentDaySelectedIconRes="@drawable/border_top_bottom"
        app:currentDayTextColor="#f79256"
        app:firstDayOfTheWeek="sunday"
        app:layout_constraintTop_toTopOf="parent"
        app:orientation="horizontal"
        app:selectedDayBackgroundColor="#FFEACA"
        app:selectedDayBackgroundEndColor="#f79256"
        app:selectedDayBackgroundStartColor="#f79256"
        app:selectedDayTextColor="#FFFFFF"
        app:selectionType="range"
        app:weekendDayTextColor="#ef4550" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="next"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/calendar_view" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

cosmo calendar에서 날짜를 하나씩, 여러개, 범위 등으로 설정해서 선택할 수 있는데 

- selectionType = "range" 로 설정해서 범위로 설정했다. 

다음 페이지로 넘기면서 선택한 날짜를 전달하고 싶어서 버튼도 추가했다.

 

 

3. 선택한 기간을 Log와 ToastMessage로 확인할 수 있게 했다. 


        binding.calendarView.selectionManager=RangeSelectionManager(OnDaySelectedListener {
            if(binding.calendarView.selectedDates.size<=0) return@OnDaySelectedListener
            Log.d("??","${binding.calendarView.selectedDays}")
            Toast.makeText(this,"${binding.calendarView.selectedDays}",Toast.LENGTH_SHORT).show()
        })

 

 

 

728x90
반응형

댓글