1. 程式人生 > >material-calendarvie 使用記錄,以及一些屬性的修改。

material-calendarvie 使用記錄,以及一些屬性的修改。

1.設定選擇的背景色

mCalendarView.setSelectionColor(Color.parseColor("#dd5050"));

2.修改選中背景顏色的大小(這裡是減少10dip)
DayView中

private void calculateBounds(int width, int height) {
    final int radius = Math.min(height, width);
    final int offset = Math.abs(height - width) / 2;

    // Lollipop platform bug. Circle drawable offset needs to be half of normal offset
    final int circleOffset =
        Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP ? offset / 2 : offset;

    if (width >= height) {
      tempRect.set(offset, 0, radius + offset, height);
      circleDrawableRect.set(circleOffset+dip_10, 0+dip_10, radius-dip_10 + circleOffset, height-dip_10)//修改選中背景的大小。
    } else {
      tempRect.set(0, offset, width, radius + offset);
      circleDrawableRect.set(0, circleOffset, width, radius + circleOffset);
    }
  }
}

3.設定週五週六週日不可點選
CalendarPagerView中

protected void updateUi() {
    for (DayView dayView : dayViews) {
      CalendarDay day = dayView.getDate();
      boolean enable = true;
      DayOfWeek dayOfWeek = day.getDate().getDayOfWeek();
      switch (dayOfWeek){//設定週五週六週日不可點選
        case FRIDAY:
        case SATURDAY: 
        case SUNDAY:
          enable = false;
          break;
      }
      dayView.setupSelection(showOtherDates, day.isInRange(minDate, maxDate)&&enable, isDayEnabled(day));
    }
    postInvalidate();
  }