如何在日历中设置特定年份?

时间:2017-02-14 14:37:33

标签: android

enter image description here enter image description here如何设置1900年代替2? 我用于日历的代码:

日期选择器图片:我想显示1900而不是2

private DatePickerDialog customDatePickerFrom() {
    DatePickerDialog dpd = new DatePickerDialog(this, mDateSetListner, mYear, mMonth, mDay);
        try {
            Field[] datePickerDialogFields = dpd.getClass().getDeclaredFields();
            for (Field datePickerDialogField : datePickerDialogFields) {
                if (datePickerDialogField.getName().equals("mDatePicker")) {
                    datePickerDialogField.setAccessible(true);
                    DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd);
                    Field datePickerFields[] = datePickerDialogField.getType().getDeclaredFields();
                    for (Field datePickerField : datePickerFields) {
                        if ("mDayPicker".equals(datePickerField.getName()) || "mDaySpinner".equals(datePickerField.getName())) {
                            datePickerField.setAccessible(true);
                            Object dayPicker = new Object();
                            dayPicker = datePickerField.get(datePicker);
                            ((View) dayPicker).setVisibility(View.GONE);
                            dpd.getDatePicker().findViewById(getResources().getIdentifier("day","id","android")).setVisibility(View.GONE);

                        }
                    }
                }
            }
        } catch (Exception ex) {
        }
    return dpd;
}

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以使用 updateDate

设置日期
datepicker.updateDate(int year, int month, int dayOfmonth);