Materialdatepicker with a spinner style - android

Using the default DatePicker class from android it was possible to make the datepicker in form of spinner like this:
But with MaterialDesignSpinner it seems that this feature by default is not implemented, as the only form looks like this:
or default textview input.
Did materialdesign remove the spinner feature, or is there a way to implementing it using the MaterialDatePicker?

I could't find a solution for the MaterialDatePicker, but I want to share my solution anyways, it works for my purpose it might for yours too:
DatePickerDialog dpd = new DatePickerDialog(this,
AlertDialog.THEME_HOLO_LIGHT,null, 1960, 1, 1);
dpd.getDatePicker().setCalendarViewShown(false);
dpd.show();
This will display the light version of the date picker dialog.
You can also use:
AlertDialog.THEME_HOLO_DARK
For a dark dialog theme or:
android.R.style.Theme_Holo_Light_Dialog
For a slightly different dialog itself.
Keep in mind to set dpd.getDatePicker().setCalendarViewShown(false); otherwise the regular calendar part of the picker is shown in addition.
If you look for more variations see this answer.

Related

Custom date picker Android - Kotlin

I'm trying to create a custom calendar in Android. I want to create somethning like this
custom calendar.
As you can see the design is slightly different than normal date picker for android. I tried to change it in xml, but like I found out, it isnt possible. So my question is - how to do that? Should I create custom class which extend from DatePicker? I was trying to find the solution by myself, but I found only answers to change color etc, but I want to also change design and font.
I will be very grateful for your help

Is it possible to switch the format of date picker header?

I am trying to change the header on material design date picker as you select a date to a different format than default. Current default is Month , year : ex: june 22, 2021, but I want it such that its Mon, June 22. It's shown on material design document as the first design, but there's no indication of how to go about changing this format?
Any ideas?
material designs : https://material.io/components/date-pickers
what I want to achieve is this :
Unfortunately, you can NOT change Date Format and Local of MaterialDatePicker.
Since MaterialDatePicker is very restricting, so as many other Material Design Components, I recommend you to use an alternate Date Picker Library such as MaterialDateTimePicker.
It basically fulfills all your needs:
Change date format: setLocale(Locale locale) ✅
Choose from multiple date UIs ✅
Very flexiable and easily customizlbe to fit your needs ✅
PS: There is one more popular alternative: android-betterpickers
Let me know if you have any other questions.
After looking into the source, and trying some things, I did find a solution. Unfortunately, it's not that simple to implement and I guess switching to MaterialDateTimePicker is still the best solution here.
The conversion from date to text for the header is done by the DateSelector via getSelectionDisplayString(Context context). See getHeaderText() inside of MaterialDatePicker here.
Sadly, MaterialDatePicker is final, so you can not simply create your own and override this method. But, with the given Builder, you can use MaterialDatePicker.Builder.customDatePicker(DateSelector selector) to place your own DateSelector (source).
Material uses their SingleDateSelector (source) for a simple date selection. But again, it's not possible to build upon this selector and write a custom getSelectionDisplayString method, because the class is restricted. Knowing this, it's needed to write your own DateSelector.
Building your own DateSelector is a bigger task on its own. It may be possible to copy from SingleDateSelector, but it's using some private classes and methods you need to copy, too.
To cut a long story short, I guess this is too much for "simply" changing the date format.

Is there an option to change Date Picker form?

I implemented date picker in my project from here: https://developer.android.com/guide/topics/ui/controls/pickers
The problem is, this date picker is in the format of regular calendar, and it takes a long time to choose faraway dates. In my app this kind of action is going to be performed all the time.
So, my question is, is there a possibility to change this calendar-like form to something faster? For example like in the picture below.
Picture of date picker i would like to make
check that library: https://github.com/florent37/SingleDateAndTimePicker
I've used it some time ago and it did almost exactly what you're looking for ;)
If it doesn't fit your needs, you can look for more 'iOS style date pickers' for Android, for example in this SO post:
ios like date/time picker for android platform
Edit:
It seems that this picker is Holo Light style and is achievable with this piece of code:
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_LIGHT,this,year,month,day);
But you need to check that on your own because they might be deprecated or not working with other themes.
Did you check this for Material Design?
Here is its documentation and code.
The DatePicker widget in Android has an attribute called android:datePickerMode that has a calendar option and a spinner option.
You can use the spinner option to get the appearance of the DatePicker you are after.

Android timepicker - similar to this in the Alarms app

In the android alarms app I have a dialog datepicker that has a keypad (image attached):
is that a standard timepicker? because I couldn't find how to do it. I found the TimePickerDialog - but that is no a keypad.
Is there a property that I'm missing or a library that does that kind of timepicker dialog?
Thanks
see this answer i have already given for this type of pickers :)
Implementing New styled date&time-pickers from android

Use Theme.Light Datepicker on Theme.Holo.Light

I have an activity that uses Theme.Holo.Light containing EditText, RadioButtons and DatePicker. I want to use Theme.Holo.Light for entire activity, except DatePicker which I want to be Theme.Light style. How can I do this?
Have you tried something like
<DatePicker
...
style="#android:style/Widget.DatePicker"/>
?
Holo uses #android:style/Widget.Holo.DatePicker while #android:style/Widget.DatePicker is the one you need to use.
Links:
Style list
Style list's source code
Update:
It seems that DatePicker is built with 3 NumberPickers. My answer is correct, but it is incomplete. The best approach I found to solve your problem was to recreate ans make your own DatePicker (copypaste from source code) and give style to the DatePicker AND the 3 NumberPickers inside.
Link of the Layout on GitHub:
DatePicker Layout

Categories

Resources