• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    Java
  • Created over 8 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

CalendarView

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

效果图

image

快速开始

在你的 build.gradle 文件里添加:

compile 'com.github.airsaid:calendarview:1.0.3'

用法示例

1、布局中:

<com.github.airsaid.library.widget.WeekView
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_marginTop="10dp"
    android:background="@android:color/white"
    app:wv_textColor="#333333"
    app:wv_textSize="14sp"/>
    
<com.github.airsaid.library.widget.CalendarView
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="@android:color/white"
    app:cv_dayBackground="@drawable/bg_day_un_selected"
    app:cv_selectDayBackground="@drawable/bg_day_selected"
    app:cv_selectTextColor="@android:color/white"
    app:cv_textColor="#333333"
    app:cv_textSize="14sp"/>

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<String> 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);

属性 & 方法

属性名 方法 作用
cv_textColor setTextColor(@ColorInt int textColor) 设置默认文字颜色
cv_selectTextColor setSelectTextColor(@ColorInt int textColor) 设置选中后文字颜色
cv_textSize setTextSize(float textSize) 设置默认文字大小
cv_selectTextSize setSelectTextSize(float textSize) 设置选中后文字大小
cv_dayBackground setDayBackground(Drawable background) 设置默认天的背景
cv_selectDayBackground setSelectDayBackground(Drawable background) 设置选中后天的背景
cv_dateFormatPattern setDateFormatPattern(String pattern) 设置日期格式化格式
cv_isChangeDateStatus setChangeDateStatus(boolean isChanged) 设置是否能够改变日期状态 (默认或选中状态)

TODO

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

联系我

More Repositories

1

AndroidLocalizePlugin

🌏 Android localization plugin. supports multiple languages and multiple translators.
Java
507
star
2

AccountBook

[停止维护] 一个数据存储使用的 Leancloud、架构采用 MVP 的记账本 APP。
Java
392
star
3

DiffuseView

This is a circle on the proliferation of Android custom view.
Java
117
star
4

Android-PickerView-Library

Simple PickerView for Android - code from https://github.com/saiwu-bigkoo/Android-PickerView
Java
112
star
5

MPermissionUtils

Android6.0 运行时权限处理工具类
Java
85
star
6

InputCodeLayout

这是一个 Android 上输入验证码的自定义布局
Java
83
star
7

sample-gradle-plugin

🚀 A powerful Gradle Plugin to help you demonstrate your android app.
Java
19
star
8

StateLayout

🌀 A customize multiple state layout for Android.
Kotlin
12
star
9

ChordView

🎸 Android custom view for rendering guitar chord.
Java
11
star
10

VerifyCodeButton

This is a custom button on Android View, used to obtain a verification code.
Java
11
star
11

OKMock

🎈 A Gradle Plugin used to quickly fill field data on Android.
Java
9
star
12

ZProgressBar

一个可动态配置颜色、弧度,带动画的自定义 ProgressBar
Java
8
star
13

TimeLineLayout

This is a simple timeline layout that applies to less data. (这是一个简单的时间轴布局,适用于数据量少的情况)
Java
8
star
14

ImageComparator

🌅 Image comparator on android.
Kotlin
7
star
15

InspireWritingPlugin

🔧 An IntelliJ IDEA plugin is used to inspire you to write code.
Kotlin
6
star
16

android-plugin-template

An android gradle plugin template.
Kotlin
5
star
17

RatingBar

RatingBar on Unity.
C#
3
star
18

CodeStatistics

📈 Code statistic build with tornadofx. supports export excel or csv.
Kotlin
2
star
19

IncrementLint

🔍 A Gradle Plugin that supports Lint increment scanning.
Kotlin
2
star