Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePickerDialog how to no show the calendar just a spinner?

I want to create a DatePickerDialog like this :

mDatePickerDialog = new DatePickerDialog(context, null /* listener */, 2000/* year */, 1/* month */, 1/* dayOfMonth */);

but with spinner like this :

enter image description here

i try to set this in the xml:

  <style name="MyDatePicker" parent="@android:style/Widget.DatePicker">
    <item name="android:calendarViewShown">false</item>
    <item name="android:datePickerMode">spinner</item>
  </style>

  <style name="MyAppTheme" parent="@android:style/Theme.Material.Light.NoActionBar"> 
    <item name="android:datePickerStyle">@style/MyDatePicker</item>
  </style>

but didn't work :(


2 Answers

I use this style to get the spinner Date picker:

<style name="MySpinnerDatePickerStyle" parent="android:Theme.Material.Dialog">
    <item name="android:datePickerStyle">@style/MySpinnerDatePicker</item>
</style>

<style name="MySpinnerDatePicker" parent="android:Widget.Material.DatePicker">
    <item name="android:datePickerMode">spinner</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:textColorPrimary">@color/white</item>
</style>
like image 141
Abuzaid Avatar answered Jun 08 '26 01:06

Abuzaid


Try make dialog with this:

DatePickerDialog dialogDatePicker = new DatePickerDialog(getActivity(), this, year, month, day);
            dialogDatePicker.getDatePicker().setCalendarViewShown(false);
            return dialogDatePicker;

UPDATE:

The setCalendarViewShown(false); is depreated so you need to set datePickerMode as spinner using xml like this:

<DatePicker
    ...
    android:datePickerMode="spinner" />
like image 39
Bruno Ferreira Avatar answered Jun 08 '26 01:06

Bruno Ferreira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!