Android date range picker

Material Design Date Picker in Android

Material Design Components (MDC Android) offers designers and developers a way to implement Material Design in their Android application. Developed by a core team of engineers and UX designers at Google, these components enable a reliable development workflow to build beautiful and functional Android applications. If you like the way how the UI elements from Google Material Design Components for android which are designed by Google are pretty awesome, then here are some steps that need to be followed to get them, and one of them is Google Material Design Components (MDC) Date Picker. There are a lot of date pickers available for Android which are Open Source. But the Material design date pickers offer more functionality to the user and easy to implement for developers. Have a look at the following images on what type of material design date pickers are going to be discussed in this discussion. Note that we are going to implement this project using the Java language. In this article, we are going to implement two types of material design date pickers as one can see in the below images.

  • Material Design Normal Date Picker
  • Material Design Date Range Picker

Skeleton of Date Picker Dialog Box

Before going to implement the material design date picker, understanding the parts of the dialog box is necessary so that it can become easier while dealing with parts of the dialog box in java code.

Steps by Step Implementation

Step 1: Create a New Project

  • To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
  • Note that select Java as the programming language.

Step 2: Adding material design components dependency

  • Now add the following dependency to the app-level gradle file.

Источник

Android date range picker

Smooth Date Range Picker is an android widget for selecting date range quickly and easily, following Material Design principle. This library is based on datetimepicker from Android frameworks and Material DateTime Picker by wdullaer.

Date Range Picker Duration Number Pad Date Range Picker Dark Theme Date Range Picker Landscape

Gradle:

Add jcenter repository into project build.gradle :

Add the following into app build.gradle :

Since SmoothDateRangePickerFragment is a subclass of DialogFragment, the usage is just like other DialogFragment.

Instantiation, the default selected date is set to today:

Instantiation, specify the default selected date:

After instantiation, remember to call

show (FragmentManager manager, String tag)

Change picker accent color:

Change picker theme to dark:

Set selectable minimal date:

Источник

Android date range picker

Another Material Time Picker for developer who do not like default Material Time Picker that difficult to use for most users.

CustomDateTimePicker is a simple Android library for displaying a DateAndTimePicker with From and To ranges as a CustomDateTimePicker . This custom picker allow user to pick both date and time in same dialog at same time.

DateTime interval picker view for Android. All-in-one day / week / month / year picker.

Android library for horizontal single row calendar. With this library, you aren’t attached to library built-in UI. You can create really beautiful and customizable UI and use selection features without hands getting dirty with RecyclerView and SelectionTracker .

A simple vertical date picker for Android, written in Kotlin.

Scroll calendar days in a vertical column infinitely.

This awesome calendar is designed to meet more complex business requirements for Android development. And it’s easy to make a custom perfect ui. This calendar is more flexible to adapt different ui and the complicated logic.

Flutter Date Picker Library that provides a calendar as a horizontal timeline.

A helper library to make date time picker dialog easily.

A library for easy usage of TimePicker on Android API 21+

PrimeCalendar provides all java.util.Calendar functionalities for Persian and Hijri dates. PrimeCalendar can be used in every JVM-based projects such as Java/kotlin applications, Android apps, etc.

This library contains three types of calendar systems as well as their conversion to each other.

First, PrimeDatePicker is a date picker tool. It provides picking a single day in addition to a range of days. Second, it is possible to use its MonthView and CalendarView as stand alone views in your project.

A simple and customisable TimePicker created in the «old» Android API 16 style. Restyled with Material 2.0 guidelines and powered by RecyclerView .

A highly customizable calendar library for Android, powered by RecyclerView.

Date Range Picker is a Calendar Picker View to show a Customized Date Range Picker with improved UI and functionality to add subtitles to the dates.

🕋Library📗aiming to calculate 🕌prayer times 🕌 with one line code. If you implement prayer times application, there is no need to do this headache again. Islam Time prayers are every complex to calculate, cause there are many variables in calculations like:

  • latitude
  • longitude
  • timezone
  • height
  • way of calculation

An android package that provides a Horizontal Date Picker.

Источник

How To Use New Material Date/DateRange Picker for Android

Hello everyone, Google recently released MaterialDatePicker: a useful new component that complies with the material design guidelines( ). This new component has a very interesting feature that allows you to select a date range instead of the old flow of selecting two dates: one «from» and one «to, i.e the component can be used as a DatePicker and a DateRangePicker. I was very excited about this and i wanted to use this in an update to a project i work on: to improve the user experience, sadly i could not find any examples or tutorials on using this lovely new component. So, I decided to make one, in this article I will be outlining the steps I took to make use of the MaterialDatePicker. This would be a really short article since, the MaterialDatePicker is really very easy to use.

1. Firstly, we have to add the Material Design component library. So in the list of dependencies in your app-level file. Add

at the time of this publication the latest release is . You can find the latest-release version number at

2. Now, we have to initialize a builder, there are two ways of doing this, depending on the type of MaterialDatePicker you want. If you want one in which you can select only one date. You can do that like so:

This would look like this:

If you need a MaterialDatePicker you can use to select a range of dates you can do that like so:

3. Now, it’s time to create the picker, irrespectively of the builder you choose, you can always create a builder by calling:

to show the picker, we call:

and thats all. However, we would always need to know what happens in our picker dialog. Let’s do this in the next step.

4. We would need to add three listeners for different scenarios, first lets handle the scenario when the dialog is cancelled:

Now, we handle the scenario, where the dialog’s negative button is clicked:

Finally, we have to cater for a successful operation. Depending on the type of MaterialDatePicker you have built, we can handle this in one of two ways. For a DatePicker, the selected value would be passed a unix epoch time value in a Long variable that is accessible as an argument in the PositiveButtonClickedListener lambda, it can also be read as a string in the header text of the Picker( Jan 10, Jul 28 etc). This is shown below

When using a date range picker the epoch values would be passed as a Pair object containing two Longs (). This can be handled as shown below:

That’s all folks, thanks for reading this till the end, i hope i have been able to shed more light on this cool new feature. Please provide feedback if you think this article can be improved. Thank you!

Источник

Android date range picker

Date pickers let users select a date or range of dates.

Contents

Using date pickers

Before you can use Material date pickers, you need to add a dependency to the Material Components for Android library. For more information, go to the Getting started page.

Date pickers let users select a date or range of dates. They should be suitable for the context in which they appear.

Date pickers can be embedded into dialogs on mobile devices.

The following image shows a date picker and a range date picker.

API and source code:

A date picker can be instantiated with MaterialDatePicker.Builder.datePicker() :

A date range picker can be instantiated with MaterialDatePicker.Builder.dateRangePicker() :

To set a default selection:

The picker can be started in text input mode with:

To show the picker to the user:

Subscribe to button clicks or dismiss events with the following calls:

Finally, you can get the user selection with datePicker.selection .

Adding calendar constraints

To constrain the calendar from the beginning to the end of this year:

To open the picker at a default month:

To set a validator:

You can also use DateValidatorPointBackward or customize by creating a class that implements DateValidator (example of a DateValidatorWeekdays in the MDC catalog).

Set the constraint to the picker’s builder:

Making date pickers accessible

Material date pickers are fully accessible and compatible with screen readers. The title of your date picker will be read when the user launches the dialog. Use a descriptive title for the task:

Calendar date picker

Calendar date pickers can be used to select dates in the near future or past, when it’s useful to see them in a calendar month format. They are displayed in a dialog.

Common use cases include:

  • Making a restaurant reservation
  • Scheduling a meeting

Date picker example

The following example shows a date picker with a date selected.

Date range pickers

Mobile date range pickers allow selection of a range of dates. They cover the entire screen.

Common use cases include:

  • Booking a flight
  • Reserving a hotel

Date range picker example

The following example shows a date range picker with a date range selected.

Anatomy and key properties

The following diagram shows the elements of a date picker:

  1. Title
  2. Selected date
  3. Switch-to-keyboard input icon
  4. Year selection menu
  5. Month pagination
  6. Current date
  7. Selected date
Element Attribute Related method(s) Default value
Style app:materialCalendarHeaderTitle N/A @style/Widget.Material3.MaterialCalendar.HeaderTitle
Text label N/A Builder.setTitleText
getHeaderText
Select Date
Color android:textColor N/A ?attr/colorOnSurfaceVariant
Typography android:textAppearance N/A ?attr/textAppearanceLabelMedium
Element Attribute Related method(s) Default value
Style app:materialCalendarHeaderSelection N/A @style/Widget.Material3.MaterialCalendar.HeaderSelection
Color android:textColor N/A ?attr/colorOnSurface
Typography android:textAppearance N/A ?attr/textAppearanceHeadlineLarge

Switch-to-keyboard input icon

Element Attribute Related method(s) Default value
Style app:materialCalendarHeaderToggleButton N/A @style/Widget.Material3.MaterialCalendar.HeaderToggleButton
Background android:background N/A ?attr/actionBarItemBackground
Color android:tint N/A ?attr/colorOnSurfaceVariant

Year selection menu

Element Attribute Related method(s) Default value
Style app:materialCalendarYearNavigationButton N/A @style/Widget.Material3.MaterialCalendar.YearNavigationButton
Text color android:textColor N/A ?attr/colorOnSurfaceVariant
Icon color app:iconTint N/A ?attr/colorOnSurfaceVariant
Element Attribute Related method(s) Default value
Style app:materialCalendarMonthNavigationButton N/A @style/Widget.Material3.MaterialCalendar.MonthNavigationButton
Text color android:textColor N/A ?attr/colorOnSurfaceVariant
Icon color app:iconTint N/A ?attr/colorOnSurfaceVariant
Element Attribute Related method(s) Default value
Style app:dayTodayStyle N/A @style/Widget.Material3.MaterialCalendar.Day.Today
Text color app:itemTextColor N/A ?attr/colorPrimary
Stroke color app:itemStrokeColor N/A ?attr/colorPrimary
Stroke width app:itemStrokeWidth N/A 1dp
Element Attribute Related method(s) Default value
Style app:daySelectedStyle N/A @style/Widget.Material3.MaterialCalendar.Day.Selected
Background color app:itemFillColor N/A ?attr/colorPrimary
Text color app:itemTextColor N/A ?attr/colorOnPrimary
Stroke color app:itemStrokeColor N/A N/A
Stroke width app:itemStrokeWidth N/A 0dp
Element Attribute Related method(s) Default value
Color app:rangeFillColor N/A ?attr/colorSurfaceVariant
Element Attribute Related method(s) Default value
Style app:materialCalendarHeaderCancelButton N/A @style/Widget.Material3.MaterialCalendar.HeaderCancelButton
Text color android:textColor N/A ?attr/colorOnSurface (see all states)
Icon color app:iconTint N/A ?attr/colorOnSurfaceVariant

Styles and theme overlays

Element Style
Default
theme overlay
ThemeOverlay.Material3.MaterialCalendar
Default style Widget.Material3.MaterialCalendar
Fullscreen
theme overlay
ThemeOverlay.Material3.MaterialCalendar.Fullscreen
Full screen style Widget.Material3.MaterialCalendar.Fullscreen

Default style theme attribute (set inside the theme overlay): ?attr/materialCalendarStyle

Default theme attribute (set on the app’s theme): ?attr/materialCalendarTheme , ?attr/materialCalendarFullscreenTheme (fullscreen)

Theming date pickers

Date pickers support Material Theming which can customize color, shape and typography.

Date picker theming example

API and source code:

The following example shows a date picker with Material Theming.

Use theme attributes and styles in `res/values/styles.xm, which apply to all date pickers and affect other components:

Use a default style theme attribute, styles and a theme overlay which apply to all date pickers but do not affect other components:

Set the theme in code, which affects only this date picker:

Источник

Читайте также:  Лучший просмотрщик изображений для андроид
Оцените статью