问题
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