when using datepicker in android 4.0 and above..ho

2019-05-06 23:15发布

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

android 2.2 image of date picker

android 4.1 image of date picker

4条回答
啃猪蹄的小仙女
2楼-- · 2019-05-07 00:00

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);
        }`
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-05-07 00:01

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)

查看更多
趁早两清
4楼-- · 2019-05-07 00:05

You can use yourDatepicker.setCalendarViewShown(false);

This method works in Api >= 11 .

查看更多
smile是对你的礼貌
5楼-- · 2019-05-07 00:20

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.

查看更多
登录 后发表回答