Pick a date or time on Android in style

Overview

Material DateTime Picker - Select a time/date in style

Join the chat at https://gitter.im/wdullaer/MaterialDateTimePicker Maven Central Build Status

Material DateTime Picker tries to offer you the date and time pickers as shown in the Material Design spec, with an easy themable API. The library uses the code from the Android frameworks as a base and tweaked it to be as close as possible to Material Design example.

Support for Android 4.1 and up. (Android 4.0 was supported until 3.6.4)

Feel free to fork or issue pull requests on github. Issues can be reported on the github issue tracker.

Version 2 Layout

Date Picker Time Picker
Date Picker Time Picker

Version 1 Layout

Date Picker Time Picker
Date Picker Time Picker

Table of Contents

  1. Setup
  2. Using Material Date/Time Pickers
  3. Implement Listeners
  4. Create Pickers
  5. Theme the Pickers
  6. Additional Options
  7. FAQ
  8. Potential Improvements
  9. License

Setup

The easiest way to add the Material DateTime Picker library to your project is by adding it as a dependency to your build.gradle

dependencies {
    implementation 'com.wdullaer:materialdatetimepicker:4.2.3'
}

You may also add the library as an Android Library to your project. All the library files live in library.

The library also uses some Java 8 features, which Android Studio will need to transpile. This requires the following stanza in your app's build.gradle. See https://developer.android.com/studio/write/java8-support.html for more information on Java 8 support in Android.

android {
  ...
  // Configure only for each module that uses Java 8
  // language features (either in its source code or
  // through dependencies).
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Using Material Date/Time Pickers

The library follows the same API as other pickers in the Android framework. For a basic implementation, you'll need to

  1. Implement an OnTimeSetListener/OnDateSetListener
  2. Create a TimePickerDialog/DatePickerDialog using the supplied factory
  3. Theme the pickers

Implement an OnTimeSetListener/OnDateSetListener

In order to receive the date or time set in the picker, you will need to implement the OnTimeSetListener or OnDateSetListener interfaces. Typically this will be the Activity or Fragment that creates the Pickers. The callbacks use the same API as the standard Android pickers.

@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
  String time = "You picked the following time: "+hourOfDay+"h"+minute+"m"+second;
  timeTextView.setText(time);
}

@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
  String date = "You picked the following date: "+dayOfMonth+"/"+(monthOfYear+1)+"/"+year;
  dateTextView.setText(date);
}

Create a TimePickerDialog/DatePickerDialog using the supplied factory

You will need to create a new instance of TimePickerDialog or DatePickerDialog using the static newInstance() method, supplying proper default values and a callback. Once the dialogs are configured, you can call show().

Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
  MainActivity.this,
  now.get(Calendar.YEAR), // Initial year selection
  now.get(Calendar.MONTH), // Initial month selection
  now.get(Calendar.DAY_OF_MONTH) // Inital day selection
);
// If you're calling this from a support Fragment
dpd.show(getFragmentManager(), "Datepickerdialog");
// If you're calling this from an AppCompatActivity
// dpd.show(getSupportFragmentManager(), "Datepickerdialog");

Theme the pickers

The library contains 2 layout versions for each picker.

  • Version 1: this is the original layout. It is based on the layout google used in the kitkat and early material design era
  • Version 2: this layout is based on the guidelines google posted when launching android marshmallow. This is the default and still the most current design.

You can set the layout version using the factory

dpd.setVersion(DatePickerDialog.Version.VERSION_2);

The pickers will be themed automatically based on the current theme where they are created, based on the current colorAccent. You can also theme the dialogs via the setAccentColor(int color) method. Alternatively, you can theme the pickers by overwriting the color resources mdtp_accent_color and mdtp_accent_color_dark in your project.

<color name="mdtp_accent_color">#009688</color>
<color name="mdtp_accent_color_dark">#00796b</color>

The exact order in which colors are selected is as follows:

  1. setAccentColor(int color) in java code
  2. android.R.attr.colorAccent (if android 5.0+)
  3. R.attr.colorAccent (eg. when using AppCompat)
  4. R.color.mdtp_accent_color and R.color.mdtp_accent_color_dark if none of the others are set in your project

The pickers also have a dark theme. This can be specified globablly using the mdtp_theme_dark attribute in your theme or the setThemeDark(boolean themeDark) functions. The function calls overwrite the XML setting.

<item name="mdtp_theme_dark">true</item>

Additional Options

[All] setThemeDark(boolean themeDark)

The dialogs have a dark theme that can be set by calling

dialog.setThemeDark(true);

[All] setAccentColor(String color) and setAccentColor(int color)

Set the accentColor to be used by the Dialog. The String version parses the color out using Color.parseColor(). The int version requires a ColorInt bytestring. It will explicitly set the color to fully opaque.

[All] setOkColor() and setCancelColor()

Set the text color for the OK or Cancel button. Behaves similar to setAccentColor()

[TimePickerDialog] setTitle(String title)

Shows a title at the top of the TimePickerDialog

[DatePickerDialog] setTitle(String title)

Shows a title at the top of the DatePickerDialog instead of the day of the week

[All] setOkText() and setCancelText()

Set a custom text for the dialog Ok and Cancel labels. Can take a resourceId of a String. Works in both the DatePickerDialog and TimePickerDialog

[DatePickerDialog] setMinDate(Calendar day)

Set the minimum valid date to be selected. Date values before this date will be deactivated

[DatePickerDialog] setMaxDate(Calendar day)

Set the maximum valid date to be selected. Date values after this date will be deactivated

[TimePickerDialog] setMinTime(Timepoint time)

Set the minimum valid time to be selected. Time values earlier in the day will be deactivated

[TimePickerDialog] setMaxTime(Timepoint time)

Set the maximum valid time to be selected. Time values later in the day will be deactivated

[TimePickerDialog] setSelectableTimes(Timepoint[] times)

You can pass in an array of Timepoints. These values are the only valid selections in the picker. setMinTime(Timepoint time), setMaxTime(Timepoint time) and setDisabledTimes(Timepoint[] times) will further trim this list down. Try to specify Timepoints only up to the resolution of your picker (i.e. do not add seconds if the resolution of the picker is minutes).

[TimePickerDialog] setDisabledTimes(Timepoint[] times)

You can pass in an array of Timepoints. These values will not be available for selection. These take precedence over setSelectableTimes and setTimeInterval. Be careful when using this without selectableTimes: rounding to a valid Timepoint is a very expensive operation if a lot of consecutive Timepoints are disabled. Try to specify Timepoints only up to the resolution of your picker (i.e. do not add seconds if the resolution of the picker is minutes).

[TimePickerDialog] setTimeInterval(int hourInterval, int minuteInterval, int secondInterval)

Set the interval for selectable times in the TimePickerDialog. This is a convenience wrapper around setSelectableTimes. The interval for all three time components can be set independently. If you are not using the seconds / minutes picker, set the respective item to 60 for better performance.

[TimePickerDialog] setTimepointLimiter(TimepointLimiter limiter)

Pass in a custom implementation of TimeLimiter Disables setSelectableTimes, setDisabledTimes, setTimeInterval, setMinTime and setMaxTime

[DatePickerDialog] setSelectableDays(Calendar[] days)

You can pass a Calendar[] to the DatePickerDialog. The values in this list are the only acceptable dates for the picker. It takes precedence over setMinDate(Calendar day) and setMaxDate(Calendar day)

[DatePickerDialog] setDisabledDays(Calendar[] days)

The values in this Calendar[] are explicitly disabled (not selectable). This option can be used together with setSelectableDays(Calendar[] days): in case there is a clash setDisabledDays(Calendar[] days) will take precedence over setSelectableDays(Calendar[] days)

[DatePickerDialog] setHighlightedDays(Calendar[] days)

You can pass a Calendar[] of days to highlight. They will be rendered in bold. You can tweak the color of the highlighted days by overwriting mdtp_date_picker_text_highlighted

[DatePickerDialog] showYearPickerFirst(boolean yearPicker)

Show the year picker first, rather than the month and day picker.

[All] OnDismissListener and OnCancelListener

Both pickers can be passed a DialogInterface.OnDismissLisener or DialogInterface.OnCancelListener which allows you to run code when either of these events occur.

tpd.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialogInterface) {
      Log.d("TimePicker", "Dialog was cancelled");
    }
});

[All] vibrate(boolean vibrate)

Set whether the dialogs should vibrate the device when a selection is made. This defaults to true.

[All] dismissOnPause(boolean dismissOnPause)

Set whether the picker dismisses itself when the parent Activity is paused or whether it recreates itself when the Activity is resumed.

[All] setLocale(Locale locale)

Allows the client to set a custom locale that will be used when generating various strings in the pickers. By default the current locale of the device will be used. Because the pickers will adapt to the Locale of the device by default you should only have to use this in very rare circumstances.

[DatePickerDialog] autoDismiss(boolean autoDismiss)

If set to true will dismiss the picker when the user selects a date. This defaults to false.

[TimepickerDialog] enableSeconds(boolean enableSconds) and enableMinutes(boolean enableMinutes)

Allows you to enable or disable a seconds and minutes picker on the TimepickerDialog. Enabling the seconds picker, implies enabling the minutes picker. Disabling the minute picker will disable the seconds picker. The last applied setting will be used. By default enableSeconds = false and enableMinutes = true.

[DatePickerDialog] setTimeZone(Timezone timezone) deprecated

Sets the Timezone used to represent time internally in the picker. Defaults to the current default Timezone of the device. This method has been deprecated: you should use the newInstance() method which takes a Calendar set to the appropriate TimeZone.

[DatePickerDialog] setDateRangeLimiter(DateRangeLimiter limiter)

Provide a custom implementation of DateRangeLimiter, giving you full control over which days are available for selection. This disables all of the other options that limit date selection.

getOnTimeSetListener() and getOnDateSetListener()

Getters that allow the retrieval of a reference to the callbacks currently associated with the pickers

[DatePickerDialog] setScrollOrientation(ScrollOrientation scrollOrientation) and getScrollOrientationi()

Determines whether months scroll Horizontal or Vertical. Defaults to Horizontal for the v2 layout and Vertical for the v1 layout

FAQ

Why does the DatePickerDialog return the selected month -1?

In the java Calendar class months use 0 based indexing: January is month 0, December is month 11. This convention is widely used in the java world, for example the native Android DatePicker.

How do I use a different version of a support library in my app?

This library depends on some androidx support libraries. Because the jvm allows only one version of a fully namespaced class to be loaded, you will run into issues if your app depends on a different version of a library than the one used in this app. Gradle is generally quite good at resolving version conflicts (by default it will retain the latest version of a library), but should you run into problems (eg because you disabled conflict resolution), you can disable loading a specific library for MaterialDateTimePicker.

Using the following snippet in your apps build.gradle file you can exclude this library's transitive appcompat library dependency from being installed.

implementation ('com.wdullaer:materialdatetimepicker:4.2.3') {
        exclude group: 'androidx.appcompat'
        exclude group: 'androidx.recyclerview'
}

MaterialDateTimepicker uses the following androidx libraries:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'

Excluding a dependency will work fine as long as the version your app depends on is recent enough and google doesn't release a version in the future that contains breaking changes. (If/When this happens I will try hard to document this). See issue #338 for more information.

How do I turn this into a year and month picker?

This DatePickerDialog focuses on selecting dates, which means that it's central design element is the day picker. As this calendar like view is the center of the design it makes no sense to try and disable it. As such selecting just years and months, without a day, is not in scope for this library and will not be added.

How do I select multiple days?

The goal of this library is to implement the Material Design Date picker. This design is focused on picking exactly 1 date (with a large textual representation at the top). It would require quite a bit of redesigning to make it useful to select multiple days. As such this feature is currently out of scope for this library and will not be added. If you happen to make a library that implements this, based on this code or not, drop me a line and I'll happily link to it.

How do I use my custom logic to enable/disable dates?

DatePickerDialog exposes some utility methods to enable / disable dates for common scenario's. If your needs are not covered by these, you can supply a custom implementation of the DateRangeLimiter interface. Because the DateRangeLimiter is preserved when the Dialog pauzes, your implementation must also implement Parcelable.

class MyDateRangeLimiter implements DateRangeLimiter {
  public MyDateRangeLimiter(Parcel in) {

  }

  @Override
  public int getMinYear() {
    return 1900;
  }

  @Override
  public int getMaxYear() {
    return 2100;
  }

  @Override
  public Calendar getStartDate() {
    Calendar output = Calendar.newInstance();
    output.set(Calendar.YEAR, 1900);
    output.set(Calendar.DAY_OF_MONTH, 1);
    output.set(Calendar.MONTH, Calendar.JANUARY);
    return output;
  }

  @Override
  public Calendar getEndDate() {
    Calendar output = Calendar.newInstance();
    output.set(Calendar.YEAR, 2100);
    output.set(Calendar.DAY_OF_MONTH, 1);
    output.set(Calendar.MONTH, Calendar.JANUARY);
    return output;
  }

  @Override
  public boolean isOutOfRange(int year, int month, int day) {
    return false;
  }

  @Override
  public Calendar setToNearestDate(Calendar day) {
      return day;
  }

  @Override
  public void writeToParcel(Parcel out) {

  }

  @Override
  public int describeContents() {
    return 0;
  }

  public static final Parcelable.Creator<MyDateRangeLimiter> CREATOR
        = new Parcelable.Creator<MyDateRangeLimiter>() {
    public MyDateRangeLimiter createFromParcel(Parcel in) {
        return new MyDateRangeLimiter(in);
    }

    public MyDateRangeLimiter[] newArray(int size) {
        return new MyDateRangeLimiter[size];
    }
  };
}

When you provide a custom DateRangeLimiter the built-in methods for setting the enabled / disabled dates will no longer work. It will need to be completely handled by your implementation.

Why do the OK and Cancel buttons have the accent color as a background when combined with the Material Components library

Material Components replaces all instances of Button with an instance of MaterialButton when using one of its regular themes: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#material-components-themes
The default version of MaterialButton uses colorPrimary as the background color. Because Material Components replaces the View replacer with their own implementation there is not much I can do to fix this from this library.

There are a few workarounds:

  • Use one of the bridge themes, which do not replace the View Inflater
  • Overwrite the style of the mdtp buttons with one that inherits from Material Components text buttons, as described here:
    <style name="mdtp_ActionButton.Text" parent="Widget.MaterialComponents.Button.TextButton.Dialog"/>
  • Overwrite the View inflater again in your application theme by adding the following statement in your application theme:
    <item name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>
    You will then need to explicitly use MaterialButton in your application rather than Button

Why are my callbacks lost when the device changes orientation?

The simple solution is to dismiss the pickers when your activity is paused.

tpd.dismissOnPause(true);

If you do wish to retain the pickers when an orientation change occurs, things become a bit more tricky.

By default, when an orientation changes occurs android will destroy and recreate your entire Activity. Wherever possible this library will retain its state on an orientation change. The only notable exceptions are the different callbacks and listeners. These interfaces are often implemented on Activities or Fragments. Naively trying to retain them would cause memory leaks. Apart from explicitly requiring that the callback interfaces are implemented on an Activity, there is no safe way to properly retain the callbacks, that I'm aware off.

This means that it is your responsibility to set the listeners in your Activity's onResume() callback.

@Override
public void onResume() {
  super.onResume();

  DatePickerDialog dpd = (DatePickerDialog) getFragmentManager().findFragmentByTag("Datepickerdialog");
  TimePickerDialog tpd = (TimePickerDialog) getFragmentManager().findFragmentByTag("TimepickerDialog");

  if(tpd != null) tpd.setOnTimeSetListener(this);
  if(dpd != null) dpd.setOnDateSetListener(this);
}

Potential Improvements

  • Landscape timepicker can use some improvement
  • Code cleanup: there is a bit too much spit and ductape in the tweaks I've done.
  • Document all options on both pickers

License

Copyright (c) 2015 Wouter Dullaert

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Set initial date for the date picker

    Set initial date for the date picker

    The android date picker has a method init to set an initial date for the datePicker dialog.

    I want to set an initial selected date for this DatePicker. If I use setMin, it disables all the past dates. Is there any easy way to do this?

               //My date
                   Calendar cal = Calendar.getInstance();
                    cal.setTimeInMillis(l);
                   dday = cal.get(Calendar.DAY_OF_MONTH);
                    dmonth = cal.get(Calendar.MONTH);
                   dyear= cal.get(Calendar.YEAR);
    
               //datepicker dialog
               Calendar now = Calendar.getInstance();
                  DatePickerDialog dpd = DatePickerDialog.newInstance(
                MainActivity.this,
                now.get(Calendar.YEAR),
                now.get(Calendar.MONTH),
                now.get(Calendar.DAY_OF_MONTH)
                       );
    
    opened by shireen028 19
  • No resource found that matches the given name (at 'layout_above' with value '@id/seconds_space')

    No resource found that matches the given name (at 'layout_above' with value '@id/seconds_space')

    thanks for the library with Gradle (compile 'com.wdullaer:materialdatetimepicker:3.0.0') in Android Studio, I'm getting this error on file (land\mdtp_time_header_label.xml). how to get rid of it?

    and one more question. does this library support picking a date range or I should implement it myself?

    opened by Lithium-HD 16
  • ViewPager PagerTitleStrip are gone when using verson 1.5.2

    ViewPager PagerTitleStrip are gone when using verson 1.5.2

    I've used this library version 1.4.1 and it works good. But as you updated the library and added multiple theme support I updated it to verson 1.5.2. Your library works very good but the titles are my viewpager are gone after doing so. I checked everything and issues arises only when I use 1.5.2 version of this library.

    bug 
    opened by nomanr 15
  • Dialog does not fit on the screen

    Dialog does not fit on the screen

    It looks like fonts used are a bit too big (at least for my phone). Title gets cropped and it looks bad. You can compare it with date picker in Inbox.

    I use Galaxy Nexus (4.65" screen @ 1280x720) running Android 5.1. screenshot_2015-04-13-11-28-34 screenshot_2015-04-13-11-28-27

    bug 
    opened by MaciejCzekanski 14
  • JalaliDatePicker

    JalaliDatePicker

    I want contribute in MaterialDateTimePicker to create jalali Calendar(https://en.wikipedia.org/wiki/Jalali_calendar ) , but I don't know how I can do this! can you help me how can start this?

    question 
    opened by FarajiMehrdad 13
  • Android P will deprecate native Fragments

    Android P will deprecate native Fragments

    It was revealed yesterday in the new android-ktx library from Google that Android P will deprecate native fragments:

    The next version of Android will deprecate the version of fragments that are part of the platform.

    https://github.com/android/android-ktx/pull/161#issuecomment-363270555

    In light of this, I think the decision here to use only native Fragments should be reconsidered.

    opened by joshfriend 12
  • Setting past date along with year range causes wrong month labels to be displayed

    Setting past date along with year range causes wrong month labels to be displayed

    I create an MDTP dialog with date set to 24.12.1897 and setYearRange(1895,2015) and setMaxDate(calendar.getInstance()) and I get the dialog presented in screenshot. Notice the year at top is set to 1897 - correctly, but the month labels display a year from future.

    This seems to happen only for 'early' years of 20-th century or earlier, not so for 2000-s. Maybe has to do with pre- or post- 1970.

    I may be able to investigate this further myself, but currently have no time, so will just report for now. Maybe you'll have a quick aha!-fix for that :)

    Version of library I use is: 2.1.1

    screenshot from 2015-12-24 13-08-36

    bug 
    opened by dimsuz 12
  • showYearPickerFirst(true) cause exception

    showYearPickerFirst(true) cause exception

    Hey, I'm using com.wdullaer:materialdatetimepicker:4.1.0 and when I try to show year picker first with showYearPickerFirst(true) it throws exception as;

    java.lang.NullPointerException: Attempt to read from field 'int com.wdullaer.materialdatetimepicker.date.MonthView.mMonth' on a null object reference
           at com.wdullaer.materialdatetimepicker.date.DayPickerView.accessibilityAnnouncePageChanged(DayPickerView.java:355)
           at com.wdullaer.materialdatetimepicker.date.DayPickerGroup.onPageChanged(DayPickerGroup.java:165)
           at com.wdullaer.materialdatetimepicker.date.DayPickerView.lambda$postSetSelection$1(DayPickerView.java:244)
           at com.wdullaer.materialdatetimepicker.date.-$$Lambda$DayPickerView$lwj6z_px0zTXu4FzUTw4TbYiZpk.run(Unknown Source:4)
           at android.os.Handler.handleCallback(Handler.java:790)
           at android.os.Handler.dispatchMessage(Handler.java:99)
           at android.os.Looper.loop(Looper.java:164)
           at android.app.ActivityThread.main(ActivityThread.java:6494)
           at java.lang.reflect.Method.invoke(Native Method)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
    

    My code is;

    val datePickerDialog = DatePickerDialog.newInstance {
                    _, year, monthOfYear, dayOfMonth ->
                    
                }
                datePickerDialog.accentColor = ContextCompat.getColor(context!!,R.color.cocoa)
                datePickerDialog.showYearPickerFirst(true)
                datePickerDialog.show(getActivity().supportFragmentManager,"DatePickerDialog")
    

    It works without showYearPickerFirst(true).

    Thank you.

    bug 
    opened by AtaerCaner 11
  • Problem with background and text color of buttons

    Problem with background and text color of buttons

    Hello and thanks for this very nice library.

    I have a strange problem that I could definitely use some help to sort things out.

    I am showing a date and time picker which I am theming a bit. My problem is that the 'ok' and 'Cancel' buttons seem to get as both background color and text color the accent color of my theme.

    Here are 2 screenshots and the related code:

    screen shot 2018-09-10 at 18 52 22
      private void startDatePicker() {
            Calendar now = Calendar.getInstance();
            DatePickerDialog dpd = DatePickerDialog.newInstance(
                    this,
                    now.get(Calendar.YEAR), // Initial year selection
                    now.get(Calendar.MONTH), // Initial month selection
                    now.get(Calendar.DAY_OF_MONTH) // Initial day selection
            );
    
            dpd.dismissOnPause(true);
            dpd.setLocale(Locale.getDefault());
            dpd.setOkText("Nice!");
            dpd.setAccentColor(0xFF46A4C3);
            dpd.setTitle("Which day will it happen?");
            dpd.setThemeDark(false);
            dpd.setVersion(DatePickerDialog.Version.VERSION_2);
            dpd.show(getActivity().getFragmentManager(), "TAG_FOR_DATE_PICKER");
        }
    

    And the time picker: screen shot 2018-09-10 at 18 52 34

    private void startTimePicker() {
            Calendar now = Calendar.getInstance();
            TimePickerDialog tpd = TimePickerDialog.newInstance(
                    this,
                    now.get(Calendar.HOUR_OF_DAY),
                    now.get(Calendar.MINUTE),
                    true);
    
            tpd.dismissOnPause(true);
            tpd.setLocale(Locale.getDefault());
            tpd.setOkText("Nice!");
            tpd.setTitle("Any specific time?");
            tpd.setThemeDark(false);
            tpd.setAccentColor(ContextCompat.getColor(getActivity(), R.color.white));
            tpd.setOkColor(ContextCompat.getColor(getActivity(), R.color.temp_color_2));
            tpd.setVersion(TimePickerDialog.Version.VERSION_2);
            tpd.show(getActivity().getFragmentManager(), "TAG_FOR_TIME_PICKER");
        }
    

    Here is my theme:

    <style name="AppTheme" parent="BaseTheme">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="windowActionBarOverlay">false</item><!-- new -->
            <item name="android:windowBackground">@color/white_alabaster</item><!-- new -->
        </style>
    
    <style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
            <item name="colorPrimary">@color/blue_picton</item>
            <item name="colorPrimaryDark">@color/blue_cerulean</item>
            <item name="colorAccent">@color/pink_hot</item>
        </style>
    

    And the colors.xml:

     <color name="colorAccent">@color/pink_hot</color>
        <!-- theme colors -->
        <color name="pink_hot">#ff62cb</color>
        <color name="pink_lavender">#fcaae1</color>
        <color name="pink_persian">#f37ecc</color>
    

    I have removed any other library that might have been colliding with the attributes of your library.

    So, my question is if you know what is causing this problem or if I can set both the background color and text color of the buttons.

    Thanks :)

    opened by OneManStudioDotSe 11
  • Showing year picker first should show month view after clicking OK

    Showing year picker first should show month view after clicking OK

    Consider this scenario: my form has some kind of birthday date field and whenever user clicks on it, date picker is shown with showYearPickerFirst=true. Let's assume that field already contains some date picked earlier and user wants to change the day or month but not a year. So my app passes some initial date to MDTP and opens it.

    The thing is that in this case when year picker is shown (first), the button OK will close the dialog while I would expect that it switches to a month view, i.e. continues the selection flow.

    Just like it does when user picks a different year.

    I.e. current flow is not very consistent in this case: If user picks another year than was preselected, the month view is shown next, but if user clicks OK on year picker (leaving the year unchanged), dialog gets closed. You could try it "live" to understand better. I feel that this is counterintuitive, but maybe it's just me?

    If you are in favor of this change, I could submit a PR - I decided to ask before trying to implement this feature. Maybe I got something wrong.

    opened by dimsuz 11
  • Can't apply in Fragment . Please help .

    Can't apply in Fragment . Please help .

    I use fragment for regestration so I face problem in this lines. please reply me is this correct or not ?

    
    DatePickerDialog dpd = DatePickerDialog.newInstance(
                    (DatePickerDialog.OnDateSetListener) getActivity(),
                    now.get(Calendar.YEAR),
                    now.get(Calendar.MONTH),
                    now.get(Calendar.DAY_OF_MONTH)
            );
    

    And suggest That what i have to write here :

    dpd.show(fm, "Datepickerdialog");

    question 
    opened by dalwadi2 11
  • i'm getting a stretched picker as if it is stretching to full screen

    i'm getting a stretched picker as if it is stretching to full screen

    opened by shayvidas 0
  • Focus  first selectable date

    Focus first selectable date

    I'm using this wdullaerMaterialDateTimePicker and is working very nicely.

    I have created a list of selectable dates and using dpd.setSelectableDays(enabledDays). I would like to see on how the datepicker to select focus to first selectable date out of the list. How can I do it.

    Please help.

    opened by nadiminti 1
  • Material design 3 layout

    Material design 3 layout

    Any plans updating to material design 3 layout?

    https://material.io/components/time-pickers

    Version 2 has accent color header background. Is it possible to configure it separately to white background?

    opened by ittna 0
  • DatePickerDialog resets to selected date's month when changing selectableDays

    DatePickerDialog resets to selected date's month when changing selectableDays

    I opened a stack overflow question with full issue details.

    Essentially, when changing datePickerDialog.selectableDays with the dialog box already open to a month that has no selectable days within it, the datePickerDialog box will jump back to the last month that had selectable dates.

    Perhaps there's a workaround for my issue? Any help would be appreciated.

    opened by sediavindivoh 0
  • Why time picker is not using declared material colors?

    Why time picker is not using declared material colors?

    Im partially using Material theme in my application. Why date picker is using its default colors, instead of my declared material colors?

    <style name="Theme.BehaWifiAndroid" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Primary brand color. -->
            <item name="colorPrimary">@color/white</item>
            <item name="colorPrimaryVariant">@color/charcoal_grey</item>
            <item name="colorOnPrimary">@color/charcoal_grey</item>
            <!-- Secondary brand color. -->
            <item name="colorSecondary">@color/blue</item>
            <item name="colorSecondaryVariant">@color/blue</item>
            <item name="colorOnSecondary">@color/black</item>
            ...
    </style>
    
    opened by Klewerro 1
Releases(v4.2.3)
  • v4.2.3(Aug 30, 2019)

  • v4.2.2(Aug 18, 2019)

  • v4.2.1(Jun 5, 2019)

  • v4.2.0(May 5, 2019)

    Changes

    Features

    Pickers now inherit from AppCompatDialogFragment rather than DialogFragment. This makes them pickup AppCompat styling, such as dialogCornerRadius. This shouldn't cause any big issues, but take care verifying the look before rolling out this version. (Fixes #588 and #504)

    Bugfixes

    Fixed #586 - Fixed a memory leak in RadialSelectorView Removed a redundant androidx.annotations.annotations dependency which could cause build issues for apps relying on this library directly Removed some memory leaks in the sample app. (Shows how to avoid leaking the pickers in your own apps)

    Get it by upgrading your build.gradle to

    dependencies {
      implementation 'com.wdullaer:materialdatetimepicker:4.2.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-v4.2.0.aar(338.71 KB)
  • v4.1.2(Feb 9, 2019)

  • v4.1.1(Jan 16, 2019)

  • v4.1.0(Nov 22, 2018)

    Changes

    Features

    Improved accessibility support in the DatePicker thanks to the awesome contribution of @laalto

    Bugfixes

    Fixed #549 - Crash when changing pages in the DatePicker through accessibility commands Fixes #539 - Added content descriptions for the arrows in the DatePicker

    Get it by upgrading your build.gradle to

    dependencies {
      implementation 'com.wdullaer:materialdatetimepicker:4.1.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-v4.1.0.aar(338.95 KB)
  • v4.0.1(Oct 9, 2018)

  • v4.0.0(Oct 8, 2018)

    Changes

    Breaking

    Dropped support for API 14 and 15 Switched support library for androidx libraries Fixed #451 - Changed implementation to use support fragments Updated build.gradle syntax

    Features

    Fixed #485 - Cancel callback fires when hitting back button Fixed #505 - Made default values in setInterval more intuitive Fixed #457 - Read custom fonts as assets rather than resources Fixed #303 - Added a few default implementations to DateRangeLimiter

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:4.0.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-4.0.0.aar(339.38 KB)
  • v3.6.4(Sep 20, 2018)

    Changes

    Bugfixes

    Fixed #499 #512 #522 - Fixed a race condition when tapping the arrows in the datepicker fast Fixed #524 - Vendored an attribute which is not necessarily present in all themes Improved documentation

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.6.4'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-3.6.4.aar(351.82 KB)
  • v3.6.3(Jul 18, 2018)

  • v3.6.2(Jul 2, 2018)

  • v3.6.1(Jun 25, 2018)

  • 3.6.0(Apr 28, 2018)

    Changes

    Features

    Fixes #295 - The DatePickerDialog now shows arrows to switch between month pages

    Bugfixes

    Fixed #463 Months with 5 weeks are correctly rendered again Fixed a minor issue with the landscape DatePicker v1 layout

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.6.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-v3.6.0.aar(350.53 KB)
  • v3.5.2(Mar 10, 2018)

  • v3.5.1(Feb 4, 2018)

  • v3.5.0(Dec 28, 2017)

    Changes

    Features

    • Fixed #144 - Support for horizontal swiping in the DatePickerDialog
    • Fixed #419 #325 - Clients can now set a custom locale instead of using the device default

    Bugfixes

    • Fixed rounding logic when only a year range is specified
    • Fixed #398 #383 - Ensure TimeZone information is properly used everywhere
    • Fixed #430 - Fixed issue where overriding the background color would not behave as expected
    • Ensured Dialogs can be reused by called initialize() again

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.5.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-v3.5.0.aar(339.35 KB)
  • v3.4.1(Dec 16, 2017)

  • v3.4.0(Nov 2, 2017)

    Changes

    Features

    Fixes #411 - Hours > 12 are shown on the inner circle in the v2 layout. This brings the layout in line with the native pickers Fixes #409 - Added getters for the current registered callback in both pickers

    Bugfixes

    Fixed some serialisation bugs

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.4.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker.v3.4.0.aar(336.53 KB)
  • v3.3.1(Sep 30, 2017)

  • v3.3.0(Aug 20, 2017)

    Changes

    Improvements

    Improves #357 - TimePickerDialog#setSelectableTimes is now backed by a TreeSet internally for a better performance Fixes #336 - Added TimePickerDialog#setDisabledTimes method Added the option of passing in a custom TimepointLimiter

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.3.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v3.2.3(Aug 15, 2017)

    Changes

    Improvements

    Added hashCode() method to Timepoint Added annotations to DateRangeLimiter (to prevent issues like #393 and #394) Fixed #390 - Updated to support library v26.0.1

    Bugfixes

    Fixed #386 - Fixed some flaky ID creation in RelativeLayouts

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.2.3'
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v3.2.2(May 25, 2017)

    Changes

    Bugfixes

    Fixed #355 - Rounding didn't work properly when releasing a drag in the TimePickerDialog

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.2.2'
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v3.2.1(May 13, 2017)

    Changes

    Bugfixes

    Fixed #349 - DefaultDateRangeLimiter wasn't serializable, leading to IO exceptions when the Activity paused Fixed #346 - Changing the DatePickerDialog swipe orientation wasn't supposed to be public yet

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.2.1'
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v3.2.0(Apr 26, 2017)

    Changes

    Features

    Fixed #312 - Datepicker is now a RecyclerView (preparing for horizontal scrolling) Fixed #339 - Added overloaded getInstance() methods which default the current selection to the current date / time Fixed #326 - Extracted date limiting functionality into an interface, so it's easier to supply custom logic

    Bugfixes

    Fixed #337 - Made OnDateChangedListener protected, so subclasses can use it Fixed #332 - Updated support library dependency

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.2.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-3.2.0.aar(319.79 KB)
  • v3.1.3(Mar 2, 2017)

  • v3.1.2(Feb 17, 2017)

    Changes

    Bugfixes

    Fixed #287 - Fixes regression when dragging in the TimePickerDialog Fixed #307 - Remove calls to API 16 methods Fixed #310 - Fix month rendering when using custom timezone Fixed #316 - Clone the arguments of setMinDate and setMaxDate

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.1.2'
    }
    
    Source code(tar.gz)
    Source code(zip)
    MaterialDateTimePicker-3.1.2.aar(315.29 KB)
  • v3.1.1(Jan 28, 2017)

    Changes

    Bugfixes

    Fixed #305 - Reduced time label size slightly so it displays properly on smaller resolutions Fixed #299 - Time picker would not properly constrain selections when dragging in the hour view Fixed #304 - Improved performance of limiting date selections Fixed #300 - Date would not format correctly when using the new TimeZone feature

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.1.1'
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v3.1.0(Jan 14, 2017)

    Changes

    Bugfixes

    Fixed #287 - The Timepicker would not keep the hour fixed when rounding to an acceptable time.

    Features

    Fixed #284 #285 - By popular demand: Colors of the OK and Cancel button can now be set in the Dialog builder Fixed #294 #289 - You can now set a specific timezone for the internal representation of dates

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.1.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Nov 20, 2016)

    Changes

    This release adds a new layout options for both pickers. This one is more in line with the updated Material Design guidelines google published when releasing Marshmallow. I haven't been able to commit as much time to this project as a used to and as such these changes have been due for well over a year.

    The DatePickerDialog is not completely finished. I still need to add horizontal scrolling to and tweak some of the margins. However I chose to release it, to get some feedback and gain some development speed (I don't have to continuously rebase master now).

    The new layout is also the default layout. You will have to explicitly set the layout version to Version.VERSION_1 if you don't want to use it.

    Furthermore, the TimePickerDialog callback has been changed to return the actual TimePickerDialog rather than the RadialPickerLayout subcomponent. This is helpful when you reuse the callback for different pickers and need to distinguish them by tag.

    Features

    Fixed #261 - TimePickerDialog callback now takes a TimePickerDialog argument Fixed #97 #62 #27 - First iteration of Marshmallow style layout.

    Get it by upgrading your build.gradle to

    dependencies {
      compile 'com.wdullaer:materialdatetimepicker:3.0.0'
    }
    
    Source code(tar.gz)
    Source code(zip)
Owner
null
Android NTP time library. Get the true current time impervious to device clock time changes

TrueTime for Android Make sure to check out our counterpart too: TrueTime, an NTP library for Swift. NTP client for Android. Calculate the date and ti

Instacart 1.3k Jan 4, 2023
A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.

SublimePicker A customizable view that provisions picking of a date, time & recurrence option, all from a single user-interface. You can also view 'Su

Vikram 2.3k Jan 4, 2023
KotlinX multiplatform date/time library

kotlinx-datetime A multiplatform Kotlin library for working with date and time. See Using in your projects for the instructions how to setup a depende

Kotlin 1.6k Jan 5, 2023
Multiplatform Date and time library for Kotlin

Klock is a Date & Time library for Multiplatform Kotlin. It is designed to be as allocation-free as possible using Kotlin inline classes, to be consis

null 681 Dec 19, 2022
Additions for Kotlin's date & time library kotlinx-datetime

fluid-time Additions for Kotlin's date & time library kotlinx-datetime. kotlinx-datetime is very early stage and not as actively developed as other of

Marc Knaup 39 Nov 11, 2022
Standalone Android widget for picking a single date from a calendar view.

TimesSquare for Android Standalone Android widget for picking a single date from a calendar view. Usage Include CalendarPickerView in your layout XML.

Square 4.4k Dec 20, 2022
MinutesAliveApp - Basic Android App that ask for your date of birth and shows your age in minutes

MinutesAliveApp Basic Android App that ask for your date of birth and shows your

JestorDev 0 Jan 30, 2022
Compose Date Picker - Select month and year

Android DatePicker with month and year build with Compose UI

Doğuş Teknoloji 47 Dec 15, 2022
A simple Cupcake Ordering App, choose flavor, pickup on a date, get order summary and send order via any other app.

Cupcake app This app contains an order flow for cupcakes with options for quantity, flavor, and pickup date. The order details get displayed on an ord

Akshat Khandelwal 0 Dec 23, 2021
Joda-Time library with Android specialization

Android has built-in date and time handling - why bother with a library? If you've worked with Java's Date and Calendar classes you can probably answer this question yourself, but if not, check out Joda-Time's list of benefits.

Daniel Lew 2.6k Dec 9, 2022
java.time Kotlin extension functions library.

Java Time Kotlin extension functions. Background Java Time became integrated to the JDK as of Java 8. It was a huge improvement over its Date predeces

Sami Eljabali 31 Mar 15, 2022
Estimated Time of Arrival Bar

Estimated Time of Arrival Bar

Tek 1 Mar 12, 2022
Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Android Week View Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling. Fea

Raquib-ul Alam (Kanak) 3.4k Jan 3, 2023
An adaptation of the JSR-310 backport for Android.

ThreeTen Android Backport An adaptation of the JSR-310 backport for Android. Attention: Development on this library is winding down. Please consider s

Jake Wharton 3.5k Dec 11, 2022
A better calendar for Android

Caldroid Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User ca

Roomorama 1.4k Nov 29, 2022
Android library for better Picker DialogFragments

DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numbers, and other things.

Code-Troopers 2.7k Dec 29, 2022
Android calendar view inspired by Sunrise calendar and iOS7 stock calendar

SilkCal Android calendar view inspired by Sunrise calendar and iOS7 stock calendar. Usage Add compile 'me.nlmartian.silkcal:library:0.1.1' to your dep

JunGuan Zhu 385 Nov 25, 2022
An android library which provides a compact calendar view much like the one used in google calenders.

CompactCalendarView CompactCalendarView is a simple calendar view which provides scrolling between months. It's based on Java's Date and Calendar clas

SundeepK 1.5k Jan 7, 2023
A Material design back port of Android's CalendarView

Material Calendar View A Material design back port of Android's CalendarView. The goal is to have a Material look and feel, rather than 100% parity wi

Prolific Interactive 5.8k Jan 3, 2023