0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kizitonwose-Calendarを使ったカレンダーUIの実装

0
Last updated at Posted at 2026-02-22

kizitonwose-CalendarViewを使用したカレンダーUIの実装方法をメモします。
kizitonwose-CalendarViewは、カレンダーUIの自由度が高く、拡張性が広いです。Composeにも対応しています。

Gradleを追加

dependencies {
    implementation("com.kizitonwose.calendar:view:x.x.x")
}

レイアウトに CalendarView を追加する

<com.kizitonwose.calendar.view.CalendarView
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

カレンダーの初期設定

val currentMonth = YearMonth.now()
val startMonth = currentMonth.minusMonths(12) // 表示開始月
val endMonth = currentMonth.plusMonths(12) // 表示終了月
val firstDayOfWeek = DayOfWeek.MONDAY // 週の開始曜日

calendarView.setup(startMonth, endMonth, firstDayOfWeek)
calendarView.scrollToMonth(currentMonth)
① 日付セル用レイアウトを作成する
<TextView
    android:id="@+id/dayText"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:gravity="center"/>
② DayBinderの実装する
class DayViewContainer(view: View) : ViewContainer(view) {
    val textView = view.findViewById<TextView>(R.id.dayText)
}

calendarView.dayBinder = object : MonthDayBinder<DayViewContainer> {

    override fun create(view: View): DayViewContainer {
        return DayViewContainer(view)
    }

    override fun bind(container: DayViewContainer, data: CalendarDay) {
        container.textView.text = data.date.dayOfMonth.toString()

        if (data.position == DayPosition.MonthDate) {
            container.textView.alpha = 1f
        } else {
            container.textView.alpha = 0.3f
        }
    }
}

これで簡単なカレンダーが実装できます。デザインを完全に自由にしたい!範囲選択や複数選択を実装したい!と言った実装が可能でUIを自由自在に作れる強力なライブラリです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?