Creating a Month and Year Picker in Android: Material User Interface

Hey, we all know that it is quite difficult to remove date from the Material Date Picker in android, but after a lot of searching I found something that does the work perfectly for my work.

I found a Library by GitHub@premkumarroyal, which does the work, it was not as easy as I was expecting because all the libraries are available in java and for being a Kotlin developer there is not any library to do so.

  • The very first thing comes is, as we all know the dependency.
  • So, first we are going to create the theme.xml or styles.xml for this month picker if you to customize the color your wish but don’t change the id of the colors.
  • Now, in activity_main.xml or any other layout xml you want it, just copy & paste the code, customization as per your choice.
  • Now, it's time to write the logic part in Activity or Fragment as per your choice, I’m writing this under an Activity.

Note: Don’t forget to activate the viewBinding feature, because I’m using viewBinding to bind the xml to the activity.

There are a lot of methods available for the convivence, don’t forgot to checkout at the GitHub repository.

  • Where you want your listener you can add to that xml object, just a single line code.
  • One more thing, I have added is an extension function which return the corresponding month string with the parameter as the month number (Integer).

Note: The most important part is to handle the Manifest merge error, just a line of replace in AndroidManifest.xml in application element.




Software Developer Intern [Mobile Developer] @OKidzLabs