• This repository has been archived on 25/Dec/2022
  • Stars
    star
    159
  • Rank 227,434 (Top 5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Date Picker

Maven Central 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):

<com.afollestad.date.DatePicker
    android:id="@+id/datePicker"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

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:

<com.afollestad.date.DatePicker
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...
    app:date_picker_selection_color="?colorAccent"
    app:date_picker_header_background_color="?colorAccent"
    app:date_picker_medium_font="@font/some_medium_font"
    app:date_picker_normal_font="@font/some_normal_font"
    app:date_picker_disabled_background_color="@color/disabled_color"
    app:date_picker_selection_vibrates="true"
    app:date_picker_calendar_horizontal_padding="4dp"
    />

(Note that in order for date_picker_selection_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())

More Repositories

1

material-dialogs

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.
Kotlin
19,658
star
2

aesthetic

[DEPRECATED]
Kotlin
2,001
star
3

drag-select-recyclerview

πŸ‘‡ Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.
Kotlin
1,962
star
4

photo-affix

πŸ“· Stitch your photos together vertically or horizontally easily!
Kotlin
1,006
star
5

material-cab

πŸš• An Android & Kotlin library for placing and manipulating Contextual Action Bars in your UI.
Kotlin
984
star
6

assent

πŸ™ Android Runtime Permissions made easy and compact, for Kotlin and AndroidX. With coroutines support!
Kotlin
853
star
7

ason

[DEPRECATED]: Prefer Moshi, Jackson, Gson, or LoganSquare
Java
759
star
8

recyclical

πŸš€ An easy-to-use, extensible Kotlin DSL for setting up and manipulating RecyclerViews.
Kotlin
715
star
9

vvalidator

πŸ€– An easy to use form validator for Kotlin & Android.
Kotlin
657
star
10

mnml

πŸ“Ή A minimal, beautiful screen recorder for Android.
Kotlin
652
star
11

nock-nock

πŸšͺ Monitor and validate your websites to maintain maximum uptime.
Kotlin
377
star
12

rxkprefs

πŸ›  A small Kotlin library to make shared preferences easy + RxJava and Coroutines support
Kotlin
277
star
13

ulfberht

πŸ—‘οΈ A small but powerful & opinionated DI library. Written in Kotlin, and powered by annotation processing.
Kotlin
251
star
14

viewpagerdots

πŸ‘€ Simple, compact Kotlin library for ViewPager page indicators.
Kotlin
189
star
15

library-template-android

A Kotlin + Android library template (with a sample project).
Kotlin
152
star
16

assure

A Kotlin library that makes biometric authentication quick and easy.
Kotlin
68
star
17

arctic-icon-request

An easy to use Icon Request API for Kotlin, with traditional email capabilities plus the Arctic Manager API.
Kotlin
59
star
18

library-template-jvm

A Kotlin/JVM library template (with a sample project).
Kotlin
46
star
19

af.codes

🌐 The source code of my personal website.
HTML
31
star
20

pi-feeder

My WIP Raspberry Pi auto pet feeder system.
CSS
31
star
21

pi-feeder-android

A simple client for my Pi Feeder IoT device. Used for discovery and basic setup, scheduling is left to the web dashboard.
Java
19
star
22

node-deploy

A Git and HTTP powered deployment system for Node.js apps.
JavaScript
8
star
23

web-recording-experiments

Experiments with recording audio and video from the web. This repo is incomplete, right now. I will be adding more.
JavaScript
4
star
24

trifles

JavaScript
3
star
25

color-render

JavaScript
3
star
26

afollestad

2
star