Date Picker in Spinner Mode |
Sometimes, It's all about Requirements.
It doesn't work on Nougat, Android 7.0+As we know that human nature is quite weird, people want things as same as they think. Which is quite hard to get, when that thing doesn't exist or incompatible with current devices. same thing is happening with date picker, Yes date picker dialog has different styles based on android OS versions.
The new date picker style is quite nice and more user friendly then previous. But if you were familiar with older one than you won't be happy with your new date picker style. see the screenshot below which is taken from Android Marshmallow.
Date Picker in Android Marshmallow |
There are so many examples to convert this calendar view into spinner mode. But some of them are quite hard to understand or some of them has huge process to achieve. Here you will find the smartest and fastest way to do it.
You can change style into Holo Dark Dialog Theme. see below screenshot.
Holo Dark Dialog Theme Date Picker |
DatePickerDialog dialog = new DatePickerDialog(getContext(), android.R.style.Theme_Holo_Dialog, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { //Todo your work here } }, yy, mm, dd); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.show();
Same as you can also change into Holo Light Dialog Theme. see below screenshot.
Holo Light Dialog Theme Date Picker |
DatePickerDialog dialog = new DatePickerDialog(getContext(), android.R.style.Theme_Holo_Light_Dialog, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { //Todo your work here } }, yy, mm, dd); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.show();
That's it, For more updates subscribe our channel now.
Why the above method(android.R.style.Theme_Holo_Dialog) doesn't work on Nougat Android 7.0+ ?
ReplyDeleteIf we want to implement it on Nougat, what we need to do?
Thanks in advance
Thanks
ReplyDeletefor this useful help
thank you
ReplyDelete