when using datepicker in android 4.0 and above..how to avoid the calender view

 ̄綄美尐妖づ 提交于 2019-12-12 09:43:09

问题


i have done a project in android 2.2 which contains a date picker and set the properties for it according to he size of screen but when i installed it in android 4.0...the date picker view includes a calender view ....what to do to avoid the calender view along with datepicker in android 4.0...below are the images of date picker in 2.2 and 4.1


回答1:


You can use yourDatepicker.setCalendarViewShown(false);

This method works in Api >= 11 .




回答2:


Use the code of Raval. But to run it below Android version 11, do following:

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 have it working on all Android versions (Above API > 3)




回答3:


In Case that you have instance of DatePicker you must write only this in your method `

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



回答4:


To avoid the Calendar in your DatePicker for later APIs

Add

android:datePickerMode="spinner"

instead of

android:calenderViewShown="false"

in your layout XML for the DatePicker widget.



来源:https://stackoverflow.com/questions/12560495/when-using-datepicker-in-android-4-0-and-above-how-to-avoid-the-calender-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!