SpinnerDatePicker Android Library

repository·master·Indexed 43 days ago

https://github.com/drawers/spinnerdatepicker

A lightweight Android library providing a spinner-style DatePicker based on the AOSP implementation. It allows for custom styling of underlying NumberPickers via the SpinnerDatePickerDialogBuilder and is suitable for use cases like date of birth selection. Requires API level 18 or higher for full styling support.

Tokens
825
Snippets
3
Records
3
Agent score
6%

What's inside SpinnerDatePicker

  1. Style the NumberPickers in SpinnerDatePicker

    master

    The SpinnerDatePicker is composed of three NumberPickers. You can customize their appearance (such as text size, color, and divider colors) by passing a style resource to .spinnerTheme() in the builder.

    Define your style in res/values/styles.xml. Use android:colorControlNormal to control the color of the horizontal dividers in the NumberPicker.

    <!-- res/values/styles.xml -->
    <style name="NumberPickerStyle">
        <item name="android:textSize">22dp</item>
        <item name="android:textColorPrimary">@color/colorAccent</item>
        <item name="android:colorControlNormal" tools:targetApi="lollipop">@color/colorAccent</item>
    </style>
  2. Install SpinnerDatePicker via JitPack

    master

    To use SpinnerDatePicker in your Android project, follow these two steps:

    1. Add the JitPack repository to your project-level build.gradle file:

    2. Add the dependency to your app-level build.gradle file.

    Note: Full styling support requires API level 18 or higher.

    // Project-level build.gradle
    allprojects {
        repositories {
            maven { url "https://jitpack.io" }
        }
    }
    
    // App-level build.gradle
    dependencies {
        compile 'com.github.drawers:SpinnerDatePicker:2.0.1'
    }
  3. Use SpinnerDatePickerDialogBuilder to show a date picker

    master

    The SpinnerDatePickerDialogBuilder provides a fluent API to configure and display the spinner-style date picker. It is designed to mimic the standard Android DatePicker API while allowing for custom styling of the underlying NumberPickers.

    Common configuration methods include:

    • .context(Context): The activity context.
    • .callback(DatePickerListener): The listener for date selection.
    • .spinnerTheme(int): A style resource for the NumberPickers.
    • .showTitle(boolean): Whether to show the title.
    • .customTitle(String): A custom string for the title.
    • .showDaySpinner(boolean): Whether to show the day spinner.
    • .defaultDate(year, month, day): The initial date selected.
    • .maxDate(year, month, day): The upper limit for selection.
    • .minDate(year, month, day): The lower limit for selection.
    new SpinnerDatePickerDialogBuilder()
            .context(MainActivity.this)
            .callback(MainActivity.this)
            .spinnerTheme(R.style.NumberPickerStyle)
            .showTitle(true)
            .customTitle("My custom title")
            .showDaySpinner(true)
            .defaultDate(2017, 0, 1)
            .maxDate(2020, 0, 1)
            .minDate(2000, 0, 1)
            .build()
            .show();