CalendarView

by Airsaid

Airsaid / CalendarView

Android 平台上继承 View 实现的自定义日历控件

126 Stars 32 Forks Last release: Not found 18 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

CalendarView

Android 平台上继承 View 实现的自定义日历控件.

效果图

image

快速开始

在你的

build.gradle
文件里添加:
compile 'com.github.airsaid:calendarview:1.0.3'

用法示例

1、布局中: ```

```

2、设置监听器: - 设置点击监听:

mCalendarView.setOnDataClickListener(new CalendarView.OnDataClickListener() {
            @Override
            public void onDataClick(@NonNull CalendarView view, int year, int month, int day) {
                Log.e("test", "year: " + year);
                Log.e("test", "month,: " + (month + 1));
                Log.e("test", "day: " + day);
            }
        });
- 设置日期选中或取消选中监听:
mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
    @Override
    public void onSelectedDayChange(@NonNull CalendarView view, boolean select, int year, int month, int day) {
        if(select){
            Toast.makeText(getApplicationContext()
                    , "选中了:" + year + "年" + (month + 1) + "月" + day + "日", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getApplicationContext()
                    , "取消选中了:" + year + "年" + (month + 1) + "月" + day + "日", Toast.LENGTH_SHORT).show();
        }
    }
});

除此之外,还有一些其他的额外方法:

  • 设置已选天数数据:

    List data = new ArrayList();
    // 这里的日期格式可以通过 setDateFormatPattern() 方法设置,默认是 yyyyMMdd
    data.add("20171229");
    data.add("20171230");
    mCalendarView.setSelectDate(data);
    
  • 设置显示指定的日期(如当前月的下个月):

    Calendar calendar = mCalendarView.getCalendar();
    calendar.add(Calendar.MONTH, 1);
    mCalendarView.setCalendar(calendar);
    
  • 设置字体:

    mCalendarView.setTypeface(typeface);
    
  • 设置是否可以点击:

mCalendarView.setClickable(boolean);

  • 设置是否可以改变日期状态:
    mCalendarView.setChangeDateStatus(boolean);
    

属性 & 方法

| 属性名| 方法| 作用 | |------------|-----------|--------| | cvtextColor| setTextColor(@ColorInt int textColor)|设置默认文字颜色 | | cvselectTextColor| setSelectTextColor(@ColorInt int textColor)|设置选中后文字颜色 | | cvtextSize| setTextSize(float textSize)|设置默认文字大小 | | cvselectTextSize | setSelectTextSize(float textSize)|设置选中后文字大小 | | cvdayBackground | setDayBackground(Drawable background)|设置默认天的背景 | | cvselectDayBackground | setSelectDayBackground(Drawable background)|设置选中后天的背景 | | cvdateFormatPattern | setDateFormatPattern(String pattern)|设置日期格式化格式 | | cvisChangeDateStatus | setChangeDateStatus(boolean isChanged)|设置是否能够改变日期状态 (默认或选中状态)|

TODO

  • [ ] 添加长按事件。
  • [ ] 自定义天的视图。
  • [ ] 添加当前天的自定义配置。

联系我

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.