Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 2.89 KB

README.md

File metadata and controls

70 lines (51 loc) · 2.89 KB

AndroidDateTimePicker

Min SDK Lincense

A date & time picker component for Android. Light themed design, fullscreen picker dialog, and native Material components only. Support setting default selected date & time, and selection result callback handler. Support custom button icon, title text, and colors. Minimum dependency of SDK 5.0.

Dependencies

Min SDK = 5.0

Main Features

  • Date & time picker
  • Default selected date & time
  • Selection result callback listener
  • Custom button icons, title text, and colors

Preview

DateTimePicker Select Date DateTimePicker Select Time

How to Use

It is very simple to set up.

DateTimePickerDialog selectDialog = new DateTimePickerDialog();
selectDialog.setDefaultDateTime(Calendar.getInstance()); //Set default selected date & time.
selectDialog.setOnResultsListener(new DateTimePickerDialog.OnResultsListener() {
    @Override
    public void onSuccess(Calendar date) {
        //Selection result callback. Parameter "date" holds the selected date & time.
    }
});
getSupportFragmentManager().beginTransaction()
    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) //Set the transition animation when dialog opens.
    .add(R.id.root_view, selectDialog) //Show dialog. "R.id.root_view" should be replaced by the ID of the activity's root view.
    .addToBackStack(null) //Add dialog to back stack.
    .commit();

(Optional) Add these to string.xmls to change the title text.

<string name="title_select_date">Select Date</string>
<string name="title_select_time">Select Time</string>

(Optional) Add these to colors.xmls to change the colors.

<color name="colorPrimary">#FFFFFF</color>
<color name="colorPrimaryDark">#FFFFFF</color>
<color name="colorAccent">#000000</color>
<color name="colorControl">#EDEDED</color>

(Optional) Add these drawables to the drawable directory to change button icons.

Drawable Name Used For Icon Size
ic_close_24.xml Close picker dialog for canceling selection button. 24dp x 24dp
ic_next_24.xml Switch from date selection to time selection button. 24dp x 24dp
ic_submit_24.xml Submit selected result button. 24dp x 24dp

License

This project is under the Apache 2.0 License.