Description
Have you ever been told to implement picker of month and year only? Then you know that standard DatePickerDialog requires selecting of exact day and makes selecting of month and year long. This library solves both this issues.
Since this and this libraries didn't have required features for my back then enterprise projects I have written this new library fully in Kotlin with usage of ideas of above-mentioned libraries. In process I have added a few more features.
MonthYearPickerDialog alternatives and similar packages
Based on the "Dialog Widget" category.
Alternatively, view MonthYearPickerDialog alternatives based on common mentions on social networks and blogs.
-
android-styled-dialogs
Backport of Material dialogs with easy-to-use API based on DialogFragment -
BlurDialogFragment
Library project to display DialogFragment with a blur effect. -
spots-dialog
Android AlertDialog with moving dots progress indicator -
LicensesDialog
LicensesDialog is an open source library to display licenses of third-party libraries in an Android app. -
Android-RateThisApp
Android library to show "Rate this app" dialog -
L-Dialogs
A small library replicating the new dialogs in android L. -
FancyGifDialog-Android
Make your native android Dialog Fancy and Gify. A library that takes the standard Android Dialog to the next level with a variety of styling options and Gif's. Style your dialog from code. -
Aesthetic Dialogs for Android 📱
📱 An Android Library for 💫fluid, 😍beautiful, 🎨custom Dialogs. -
FileListerDialog
A simple file/ directory picker dialog for android -
LongPressPopup
Make a Popup appear long pressing on a view and handle drag-release events on its elements -
PostOffice
This is a library for easily constructing Holo and Material Design Dialogs. -
AndroidSliderPreference
Android library that allows applications to add dialog-based slider widgets to their settings -
AwesomeDialog
No description, website, or topics provided. -
SimpleDialogFragment
An Android library that provides a simple implementation of a DialogFragment -
GenericDialog
A new AlertDialog for Android is here...!! -
WhatIsNewDialog
An Android library for displaying a dialog where it presents new features in the app. -
Bottom Flux Dialog
🌠 Simple way make your beautiful dialog (Bottom Sheet Dialog)
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of MonthYearPickerDialog or a related project?
README
Have you ever been told to implement picker of month and year only? Then you know that standard DatePickerDialog requires selecting of exact day and makes selecting of month and year long. This library solves both this issues.
Since this and this libraries didn't have required features for my back then enterprise projects I have written this new library fully in Kotlin with usage of ideas of above-mentioned libraries. In process I have added a few more features.
Examples of usage
Creating usual picker is simple: MonthYearPickerDialog.Builder( context = this, themeResId = R.style.Style_MonthYearPickerDialog, onDateSetListener = { year, month -> // do something } ) .build() You will get a picker with all months and years ranging from 1970 to the current year available for selection.
You can set the initially selected month and year: MonthYearPickerDialog.Builder( context = this, themeResId = R.style.Style_MonthYearPickerDialog, onDateSetListener = { year, month // do something }, selectedYear = initialYear, selectedMonth = initialMonth ) .build()
You can change button's text and add dialog's title with standard method: val dialog = MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Orange, { year, month -> // do something }, initialYear, initialMonth ) .setNegativeButton("Return") .setPositiveButton(R.string.set) .build()
dialog.setTitle("Select month and year")
Custom header with standard method: val dialog = MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Orange, { year, month -> // do something }, initialYear, initialMonth ) .setNegativeButton("Return") .setPositiveButton(R.string.set) .build()
dialog.setCustomTitle(layoutInflater.inflate(R.layout.header, null))
There are methods in the builder to set minimum month and year (default to January and 1970 respectively): MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Orange, { year, month -> // do something }, 2020, Calendar.JULY ) .setMinMonth(Calendar.MAY) .setMinYear(2020) .build() In example below this combination is set to May 2020. With years above minimum year it's possible to select all months including below minimum month. But if after this select 2020, selected month will change to May to set combination of minimum month and year.
There are methods in the builder to set maximum month and year (default to December and current year respectively): MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Orange, { year, month -> // do something }, 2022, Calendar.FEBRUARY ) .setMaxMonth(Calendar.MARCH) .setMaxYear(2022) .build() Same logic regarding limit is applied:
Limits can be combined. Example below shows how to let selection of month in range from May 2018 to February 2022. MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Red, { year, month -> // do something }, 2022, Calendar.FEBRUARY ) .setMinMonth(Calendar.MAY) .setMinYear(2018) .setMaxMonth(Calendar.FEBRUARY) .setMaxYear(2022) .build()
If you want to let selection of month from same range of months for every year, then there's special mode for this: MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Red, { year, month -> // do something }, 2022, Calendar.JULY ) .setAnnualMode(true) .setMinMonth(Calendar.MAY) .setMinYear(2018) .setMaxMonth(Calendar.AUGUST) .setMaxYear(2022) .build() It will drastically change behaviour of picker comparing to the previous example:
There are mode for selection of month only and listener of when user has selected month (notice how label changes immediately after click on month without click on dialog's positive button). Also there is method to set month format: MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Red, selectedMonth = Calendar.FEBRUARY ) .setMinMonth(Calendar.FEBRUARY) .setMaxMonth(Calendar.JULY) .setMonthFormat("MMM") .setMode(MonthYearPickerDialog.Mode.MONTH_ONLY) .setOnMonthSelectedListener { month -> // do something } .build()
There are mode for selection of year only and listener of when user has selected year: MonthYearPickerDialog.Builder( this, R.style.Style_MonthYearPickerDialog_Red, selectedYear = 2022 ) .setMinYear(2010) .setMode(MonthYearPickerDialog.Mode.YEAR_ONLY) .setOnYearSelectedListener { month -> // do something } .build()
With this you even can transform picker into any sequential number picker:
Styling
You can style your dialog with required parameter themeResId in the builder. Next attributes will help you to do this:
<attr name="headerBackgroundColor" format="color|reference" />
<attr name="headerTextColor" format="color|reference" />
<attr name="headerTextColorSelected" format="color|reference" />
<attr name="monthBackgroundColorSelected" format="color|reference" />
<attr name="monthTextColor" format="color|reference" />
<attr name="monthTextColorDisabled" format="color|reference" />
<attr name="monthTextColorSelected" format="color|reference" />
<attr name="yearTextColor" format="color|reference" />
<attr name="yearTextColorSelected" format="color|reference" />
Documentation
Installation
Library can be fetched from MavenCentral
Gradle
implementation 'io.github.dzmitry-lakisau:month-year-picker-dialog:1.0.0'
Maven
<dependency>
<groupId>io.github.dzmitry-lakisau</groupId>
<artifactId>month-year-picker-dialog</artifactId>
<version>1.0.0</version>
</dependency>
License
Copyright © 2021 Dzmitry Lakisau
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.
*Note that all licence references and agreements mentioned in the MonthYearPickerDialog README section above
are relevant to that project's source code only.