date-picker

by afollestad

afollestad / date-picker

πŸ“… Custom responsive date picker widget for Android, written in Kotlin.

135 Stars 18 Forks Last release: over 1 year ago (0.6.1) Apache License 2.0 121 Commits 17 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Date Picker

Bintray Android CI Codacy Badge License


Gradle Dependency

dependencies {
  ...
  implementation 'com.afollestad:date-picker:0.6.1'
}

Why?

Android includes a stock

DatePicker
in its framework, however this widget is very stubborn. It does not adapt to different view widths, making it difficult to use in modern UI. This library solves for that by creating a custom implementation, written completely in Kotlin.

Basics

It's simple, just add a

DatePicker
to your layout (with the fully qualified package name):

There are a few basic getters and setters:

val datePicker: DatePicker = // ...

val selectedDate: Calendar? = datePicker.getDate()

datePicker.setDate( year = 2019, month = Calendar.JUNE, selectedDate = 17 ) datePicker.setDate(Calendar.getInstance())


Styling

You can configure basic theme properties from your layout:


(Note that in order for datepickerselection_vibrates=true to have an effect, your app needs to declare the

VIBRATE
permission in its manifest.)


Callback

val datePicker: DatePicker = // ...

datePicker.addOnDateChanged { previousDate, newDate-> // this library provides convenience extensions to Calendar like month, year, and dayOfMonth too. }

// Removes all callbacks you've added previously with addOnDateChanged(...) datePicker.clearOnDateChanged()


Min and Max Dates

val datePicker: DatePicker = // ...

val minDate = datePicker.getMinDate() datePicker.setMinDate( year = 2019, month = Calendar.JUNE, date = 17 ) datePicker.setMinDate(Calendar.getInstance())

val maxDate = datePicker.getMaxDate() datePicker.setMaxDate( year = 2019, month = Calendar.JUNE, date = 20 ) datePicker.setMaxDate(Calendar.getInstance())

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.