A slide date picker for Android.
This library uses AndroidX library. If your project uses Android Support Library, consider migrating your project to AndroidX.
Add this to project level build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency into you app level build.gradle
implementation 'com.github.niwattep:material-slide-date-picker:v2.0.0'
Slide Date Picker implements DialogFragment so that it will retain its state when configuration change happens. You can show the dialog by using supportFragmentManager of an activity (or childFragmentManager of a fragment).
SlideDatePickerDialog.newInstance().show(supportFragmentManager, "TAG")
You can show the dialog using its builder.
SlideDatePickerDialog.Builder().build().show(supportFragmentManager, "TAG")
Your activity or fragment must implement interface SlideDatePickerDialogCallback
.
class MainActivity : AppCompatActivity(), SlideDatePickerDialogCallback {
override fun onPositiveClick(day: Int, month: Int, year: Int, calendar: Calendar) {
tvDate.text = SimpleDateFormat("EEEE, MMM dd, yyyy").format(calendar.time)
}
SlideDatePickerDialog.Builder()
.setStartDate(startCalendar)
.setEndDate(endCaledar)
.setPreselectedDate(todayCalendar)
.setYearModifier(543)
.setLocale(Locale("th"))
.setThemeColor(Color.RED)
.setHeaderTextColor(Color.WHITE)
.setHeaderDateFormat("EEE dd MMMM")
.setShowYear(true)
.setCancelText("Cancel")
.setConfirmText("Confirm")
.build()
.show(supportFragmentManager, "TAG")
There are 11 things you can customize:
StartDate
-Calendar
object of minimum available date (default value is January 1st, current year - 100)EndDate
-Calendar
object of maximum available date (default value isCalendar.getInstance()
)PreselectedDate
- Date that is selected when start the dialog (dafault value isCalendar.getInstance()
)YearModifier
- When you want to show year in diffent format (default is 0)Locale
- Locale for formatting date (default isLocale.US
)ThemeColor
- Color of dialogHeaderTextColor
- Color of display dateHeaderDateFormat
- Format of display dateShowYear
- Show or hide year of display dateCancelText
- String of cancel buttonConfirmText
- String of confirm button
This library is inspired by https://github.com/akexorcist/Android-SnapTimePicker
Give me a cup of coffee โ