LazyDatePicker Documentation

repository·master·Indexed 18 days ago

https://github.com/lopspower/lazydatepicker

An Android library providing a customizable alternative to the native Android Date Picker. It supports standard Date and ThreeTenABP LocalDate objects via LazyDatePicker and LazyLocalDatePicker, offering XML attributes for text and hint colors, date formats, and resource overrides for labels and dimensions.

Tokens
1.3K
Snippets
4
Records
6
Agent score
13%

What's inside LazyDatePicker

  1. Use LazyLocalDatePicker for LocalDate support

    master

    If you are using the ThreeTenABP library, use LazyLocalDatePicker instead of LazyDatePicker. This provides methods that work with LocalDate instead of java.util.Date.

    XML Usage

    <com.mikhaellopez.lazydatepicker.LazyLocalDatePicker
        android:id="@+id/lazyDatePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:ldp_text_color="@color/primary"
        app:ldp_hint_color="@color/accent"
        app:ldp_date_format="mm-dd-yyyy" />

    Kotlin Usage

    lazyLocalDatePicker.setDateFormat(LazyDatePicker.DateFormat.MM_DD_YYYY)
    lazyLocalDatePicker.setMinLocalDate(minDate)
    lazyLocalDatePicker.setMaxLocalDate(maxDate)
    
    // The localdate when is selected
    lazyLocalDatePicker.setOnLocalDatePickListener { localDateSelected ->
        //...
    }
    
    // True or false when date is selected
    lazyLocalDatePicker.setOnLocalDateSelectedListener { dateSelected ->
        //...
    }
  2. Override LazyDatePicker resources

    master

    You can customize the library's appearance by overriding specific resources in your project's strings.xml and dimens.xml.

    Override Day, Month, and Year labels

    In strings.xml:

    <string name="ldp_day" tools:override="true">D</string>
    <string name="ldp_month" tools:override="true">M</string>
    <string name="ldp_year" tools:override="true">Y</string>

    Override dimensions

    In dimens.xml:

    <dimen name="lazy_date_picker_width_case" tools:override="true">12dp</dimen>
    <dimen name="lazy_date_picker_height_focus" tools:override="true">2.5dp</dimen>
    <dimen name="lazy_date_picker_width_margin" tools:override="true">1dp</dimen>
    <dimen name="lazy_date_picker_width_space" tools:override="true">6dp</dimen>

    Redefine the entire layout

    You can completely redefine the picker's layout by creating a file named layout_lazy_date_picker.xml in your project and ensuring you keep all the original IDs.

  3. Use LazyDatePicker in Kotlin

    master

    Interact with the LazyDatePicker instance in Kotlin to set date constraints, formats, and listeners for date changes.

    lazyDatePicker.setDateFormat(LazyDatePicker.DateFormat.MM_DD_YYYY)
    lazyDatePicker.setMinDate(minDate)
    lazyDatePicker.setMaxDate(maxDate)
    
    // The date when is selected
    lazyDatePicker.setOnDatePickListener { dateSelected ->
        //...
    }
    
    // True or false when date is selected
    lazyDatePicker.setOnDateSelectedListener { dateSelected ->
        //...
    }
  4. Use LazyDatePicker in Java

    master

    Interact with the LazyDatePicker instance in Java to set date constraints, formats, and listeners for date changes.

    LazyDatePicker lazyDatePicker = findViewById(R.id.lazyDatePicker);
    lazyDatePicker.setDateFormat(LazyDatePicker.DateFormat.MM_DD_YYYY);
    lazyDatePicker.setMinDate(minDate);
    lazyDatePicker.setMaxDate(maxDate);
    
    lazyDatePicker.setOnDatePickListener(new LazyDatePicker.OnDatePickListener() {
        @Override
        public void onDatePick(Date dateSelected) {
            //...
        }
    });
    
    lazyDatePicker.setOnDateSelectedListener(new LazyDatePicker.OnDateSelectedListener() {
        @Override
        public void onDateSelected(Boolean dateSelected) {
            //...
        }
    });
  5. Configure LazyDatePicker in XML

    master

    Add the LazyDatePicker view to your layout XML. You can customize its appearance using the following attributes:

    PropertyTypeDefaultDescription
    app:ldp_text_colorcolorBLACKColor of the text
    app:ldp_hint_colorcolorGRAYColor of the hint
    app:ldp_date_formatstringmm-dd-yyyyFormat: mm-dd-yyyy or dd-mm-yyyy
    app:ldp_show_full_datebooleantrueWhether to show the full date
    <com.mikhaellopez.lazydatepicker.LazyDatePicker
        android:id="@+id/lazyDatePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:ldp_text_color="@color/primary"
        app:ldp_hint_color="@color/accent"
        app:ldp_date_format="mm-dd-yyyy" />