Spinner Picker Dialogs on Android 7.
0: We Fixed Them!Lucas NewcomerBlockedUnblockFollowFollowingJan 9The SummaryThe DatePickerDialog and TimePickerDialog are great tools for getting date/time information from a user on an Android device.
Of course, that is when the tools work as you expect them to.
On Android 7.
0, datepickermode=”spinner” and timepickermode=”spinner” attributes do not seem to work for those dialog views and the default design implementations are always visible.
This is very problematic because we, at Ibotta, feel these default implementations are not intuitive for 7.
So we decided to fix them and make the solutions into an open source library!The ProblemRecently the Ibotta Android team updated our DatePickerDialog in the Ibotta app to always appear in the spinner mode by applying datepickermode=”spinner” to the dialog’s theme.
We made the change and walked away thinking everything was fine and dandy.
A couple months later though, we learned that the DatePickerDialog is still showing up for some users in the default calendar design.
“Why, though?” is the thought that immediately came to our heads.
Alas, we jumped into action and started debugging the issue.
After some quick investigation, we figured out that the issue was only happening on devices running Android 7.
0 and it’s a known issue in the community.
We also found out that the spinner mode is not working for the TimePickerDialog for seemingly the same reason.
After this investigation, we looked to Google to see if they had workarounds, but we found nothing.
Two examples of issues reported can be found here and here.
We then searched for possible third-party fixes but ended up finding pretty complicated code that seemed hacky.
Also, these fixes weren’t bundled into libraries and therefore not plug-and-play.
For example, one approach dealt with tapping into the onCreateView method of an Activity/Fragment to access when a DatePicker view is created.
Then the process involved removing and replacing the Android platform library'sDatePicker’s XML , with a DatePicker XML file that you created.
Lastly, the implementation would do some complicated logic to update the theme of this newly replaced DatePicker view to display in the spinner fashion.
This was just one approach but other approaches were just as nasty.
Due to this unsuccessful search for a quick and clean fix to the issue, we at Ibotta decided to take the challenge head-on!The SolutionThe main question that led me to my solution was: Why would datepickermode=”spinner” work for a DatePicker that I create in XML and not for the Android platform library’s DatePicker?.???? .
After pondering this thought, I decided to create a custom DatePickerDialog class and DatePicker XML file that mimicks the platform library’s class and XML file.
I then implemented this custom DatePickerDialog and applied a dialog theme to the class with datepickermode=”spinner” and everything worked as expected!.After successfully fixing the issue for the DatePickerDialog, I attempted the same solution for the same problem that the TimePickerDialog has on Android 7.
0 and huzzah!.It fixed that issue too.
The only difference from my classes to the Android platform library’s picker dialog classes is that the library has some specific logic in the classes like setting the dialog mode to true on the picker view and adding a validation callback to the picker view.
These differences do not seem like they could be the culprit to the problem though.
I wish I had a more concrete answer to why the custom DatePickerDialog and TimePickerDialog I create correctly applies the theme attributes to the DatePicker and the platform library’s classes do not.
I assume that the platform library is doing something special with the theme attributes that causes a bug for 7.
0 devices, but that is still a mystery.
0 before solution (LEFT) and after solution (RIGHT)Taking It A Step FurtherAfter successfully fixing the spinner issue for picker dialogs on Android 7.
0, I decided to take this fix a little bit further.
I went ahead and made the fix into an open-source library, so others can use it in their apps.
I am a developer who believes in working smarter, not harder.
I use good third party libraries all the time to make development quicker/easier and I am happy to be able to pay it forward!The ConclusionUsing the DatePickerDialog and TimePickerDialog in a spinner fashion can be a great way for users to enter data into your app.
If you still support Android 7.
0 devices though and you want to be able to have spinner picker dialogs appear in your app, check out Ibotta’s open source library which provides a simple fix to this issue.
If you have any questions, feel free to use the comment thread below!.We’re happy to share our experience with you.
We’re Hiring!If these kinds of projects and challenges sound interesting to you, Ibotta is hiring!.Check out our jobs page for more information.
.. More details