Setting MinDate on DatePicker moves CalendarView to 1964

后端 未结 5 1699
离开以前
离开以前 2020-12-08 16:40

I\'m debugging an issue where the CalendarView in a DatePicker moves to October 1964 if there is a non-default minimum date set. This reproduces at

5条回答
  •  执笔经年
    2020-12-08 16:53

    I agree with @laalto. The original CalendarView is a total mess. I also had problems with the locales, the font size on Android 4.1.2 (oh yeah and it was shifted down), the lack of accessibility features, etc. So I decided to copy the source code and implement my own calendar. For example, now the header text is displayed correctly.

    /**
     * The source code has the Year 2038 problem and doesn't honor CalendarView's mCurrentLocale.
     */
    private void setMonthDisplayed(Calendar calendar) {
        mMonthName.setText(DateFormat.format("MMMM, yyyy", calendar));
        mMonthName.invalidate();
    
        mCurrentMonthDisplayed = calendar.get(Calendar.MONTH);
        mAdapter.setFocusMonth(mCurrentMonthDisplayed);
    }
    
    /**
     * This imlementation formats the date correctly and uses the stand-alone form of a month (for the languages where it's important).
     */
    private void setMonthDisplayed(Calendar calendar) {
        mMonthName.setText(new SimpleDateFormat("LLLL yyyy", mCurrentLocale).format(calendar.getTime()));
        mMonthName.invalidate();
    
        mCurrentMonthDisplayed = calendar.get(Calendar.MONTH);
        mAdapter.setFocusMonth(mCurrentMonthDisplayed);
    }
    

提交回复
热议问题