When using datepicker in android 4.0 and above. How to avoid viewing a calendar

I made a project in android 2.2 that contains a date picker and set properties for it according to the size of the screen, but when I set it up in android 4.0 ... the date picker view includes a calendar view .... What to do to avoid view calendar along with datepicker in android 4.0 ... below are images for selecting dates in 2.2 and 4.1

android 2.2 image of date picker

android 4.1 image of date picker

+4
source share
4 answers

You can use yourDatepicker.setCalendarViewShown(false);

This method works in Api >= 11 .

+12
source

Use the Raval code. But to run it under Android version 11, follow these steps:

 int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= 11) { try { Method m = datePicker.getClass().getMethod("setCalendarViewShown", boolean.class); m.invoke(datePicker, false); } catch (Exception e) {} // eat exception in our case } 

Now you are working on all versions of Android (above API> 3)

+3
source

In case you have an instance of DatePicker, you should write only this in your `

  int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= 11) { yourDatePickerInstance.setCalendarViewShown(false); }` 
+1
source

To avoid the calendar in your DatePicker for later APIs

Add

 android:datePickerMode="spinner" 

instead

 android:calenderViewShown="false" 

in your XML layout for the DatePicker widget.

0
source

Source: https://habr.com/ru/post/1435859/


All Articles