11

I tried to switch to calendar to spinner mode in DatePicker by changing setSpinnersShown and setCalendarViewShown value programmatically, but in API 24, Android Studio shows the deprecated warning.

What is the alternative ways for me to set my DatePicker from calendar to spinner mode programmatically without set values on XML in API 24. Thank you.

Ruan_Lopes
  • 1,381
  • 13
  • 18
Vinh Nguyen
  • 610
  • 7
  • 16
  • Did you ever find an answer to this question? It seems strange that a method was deprecated in such a way that it no longer seems possible to achieve this functionality. – Michael Jan 02 '17 at 01:03
  • 1
    I still don't find any answers to this question ... – Vinh Nguyen Jan 03 '17 at 02:41

2 Answers2

0

Add the attribute calendarViewShown and set it to false in xml:

<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/date_field"
android:calendarViewShown="false"/>
Palash kosta
  • 16,470
  • 1
  • 11
  • 8
0

I had a similar problem when trying to generate a Jetpack Compose wrapper where I've created a date picker in wheel style. Fixed it like this (xml needed in styles.xml but no layout files needed):

In styles.xml

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

    <style name="datepicker_dark">
        <item name="android:datePickerStyle">@style/SpinnerMode</item>
        <!-- Text color -->
        <item name="android:textColorPrimary">...</item>
    </style>

And instantiate the Picker like this:

val customContext = androidx.appcompat.view.ContextThemeWrapper(context, R.style.datepicker_dark)

DatePicker(customContext).apply {
    this.updateDate(2023, 6, 1)
    // ...
}
Vama
  • 208
  • 1
  • 13