implementation 'com.github.edasich:widget-time:LATEST_VERSION'
Add DateTimeSwitcher
in xml.
<com.github.edasich.widget.time.DateTimeSwitcher
android:id="@+id/dateTimeSwitcher"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Currently, supported modes are Day, Week, Month and Year.
To change the mode just set the new mode to DateTimeSwitcher
:
dateTimeSwitcher.switchMode = SwitchMode.DAY
When mode is changed, start and end dates are evaluated based on mode.
When dates are being changed by pressing next
and previous
buttons, title
is updated based on evaluated start
and end
dates.
To apply your custom date format for title
, use DateTimeSwitcherAdapter
.
dateTimeSwitcher.adapter = object : DateTimeSwitcherAdapter() {
override fun getTitle(
switchMode: SwitchMode,
startDateTime: LocalDateTime,
endDateTime: LocalDateTime
): String {
..
}
}
dateTimeSwitcher.setOnSwitchChangedListener { switchMode, startDateTime, endDateTime ->
..
}
dateTimeSwitcher.setOnNextClickListener { switchMode, startDateTime, endDateTime ->
..
}
dateTimeSwitcher.setOnPreviousClickListener { switchMode, startDateTime, endDateTime ->
..
}
This library is using LocalDateTime
, LocalDate
and LocalTime
which are part of java.time
package.
In order to use this library please read this official doc core android library desugaring.