我想在DialogFragment中展示一个日期选择器:
public class DatePickerDialogFragment extends DialogFragment {
private OnDateSetListener dateSetListener = null;
private String title = null;
public DatePickerDialogFragment() {}
public DatePickerDialogFragment(OnDateSetListener dateSetListener, String title) {
this.dateSetListener = dateSetListener;
this.title = title;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this.getActivity(), this.dateSetListener, year, month, day);
datePickerDialog.getDatePicker().setCalendarViewShown(false);
datePickerDialog.setTitle(this.title);
return datePickerDialog;
}
}
很遗憾,datePickerDialog.getDatePicker().setCalendarViewShown(false);
这个代码完全被忽略了。我讨厌日历视图,因为它很丑陋不舒适。那么我该如何禁用它呢?
android:calendarViewShown="false" android:datePickerMode="spinner"
。 - ApurvadatePickerDialog.getDatePicker().setCalendarViewShown(false);
,但在API<11中无法正常工作。 - Apurva