https://github.com/huanghaibin-dev/CalendarView
/**
* 定制高仿魅族日历界面,按你的想象力绘制出各种各样的界面
* Created by huanghaibin on 2017/11/15.
*/
public class MeiZuMonthView extends MonthView {
/**
* 绘制选中的日子
*
* @param canvas canvas
* @param calendar 日历日历calendar
* @param x 日历Card x起点坐标
* @param y 日历Card y起点坐标
* @param hasScheme hasScheme 非标记的日期
* @return 返回true 则绘制onDrawScheme,因为这里背景色不是是互斥的,所以返回true
*/
@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
//这里绘制选中的日子样式,看需求需不需要继续调用onDrawScheme,需要则return true
return true;
}
/**
* 绘制标记的事件日子
*
* @param canvas canvas
* @param calendar 日历calendar
* @param x 日历Card x起点坐标
* @param y 日历Card y起点坐标
*/
@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
//这里绘制标记的日期样式,想怎么操作就怎么操作
}
/**
* 绘制文本
*
* @param canvas canvas
* @param calendar 日历calendar
* @param x 日历Card x起点坐标
* @param y 日历Card y起点坐标
* @param hasScheme 是否是标记的日期
* @param isSelected 是否选中
*/
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
//这里绘制文本,不要再问我怎么隐藏农历了,不要再问我怎么把某个日期换成特殊字符串了,要怎么显示你就在这里怎么画,你不画就不显示,是看你想怎么显示日历的,而不是看框架
}
}
<attr name="month_view" format="string" />
<attr name="week_view" format="string" />
app:month_view="com.haibin.calendarviewproject.MeiZuMonthView"
app:week_view="com.haibin.calendarviewproject.MeiZuWeekView"
mCalendarView.setWeekView(MeizuWeekView.class);
mCalendarView.setMonthView(MeizuMonthView.class);
<com.haibin.calendarview.CalendarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:default_status="shrink"
app:calendar_show_mode="only_week_view"
app:calendar_content_view_id="@+id/recyclerView">
<com.haibin.calendarview.CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
app:month_view="com.haibin.calendarviewproject.simple.SimpleMonthView"
app:week_view="com.haibin.calendarviewproject.simple.SimpleWeekView"
app:week_bar_view="com.haibin.calendarviewproject.EnglishWeekBar"
app:calendar_height="50dp"
app:current_month_text_color="#333333"
app:current_month_lunar_text_color="#CFCFCF"
app:min_year="2004"
app:other_month_text_color="#e1e1e1"
app:scheme_text="假"
app:scheme_text_color="#333"
app:scheme_theme_color="#333"
app:selected_text_color="#fff"
app:selected_theme_color="#333"
app:week_start_with="mon"
app:week_background="#fff"
app:month_view_show_mode="mode_only_current"
app:week_text_color="#111" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" />
com.haibin.calendarview.CalendarLayout>
<attr name="calendar_show_mode">
<enum name="both_month_week_view" value="0" />
<enum name="only_week_view" value="1" />
<enum name="only_month_view" value="2" />
attr>
<attr name="default_status">
<enum name="expand" value="0" />
<enum name="shrink" value="1" />
attr>
<attr name="calendar_content_view_id" format="integer" />
CalendarView.scrollToCalendar();
CalendarView.scrollToNext();
CalendarView.scrollToPre();
CalendarView.scrollToXXX();
app:week_start_with="mon、sun、sat"
CalendarView.setWeekStarWithSun();
CalendarView.setWeekStarWithMon();
CalendarView.setWeekStarWithSat();
public class CustomRangeMonthView extends RangeMonthView{
}
public class CustomRangeWeekView extends RangeWeekView{
}
然后你需要设置选择模式为范围模式:select_mode="range_mode"
酒店式日历场景当然是不能从昨天开始订房的,也不能无限期订房,所以你需要静态或动态设置日历范围、精确到具体某一天!!!
CalendarView.setRange(int minYear, int minYearMonth, int minYearDay,
int maxYear, int maxYearMonth, int maxYearDay)
//设置日期拦截事件
mCalendarView.setOnCalendarInterceptListener(new CalendarView.OnCalendarInterceptListener() {
@Override
public boolean onCalendarIntercept(Calendar calendar) {
//这里写拦截条件,返回true代表拦截
return calendar.isWeekend();
}
@Override
public void onCalendarInterceptClick(Calendar calendar, boolean isClick) {
//todo 点击拦截的日期回调
}
});
boolean isInRange = isInRange(calendar);//日期是否在范围内,超出范围的可以置灰
boolean isEnable = !onCalendarIntercept(calendar);//日期是否可用,没有被拦截,被拦截的可以置灰
也许你只需要像原生日历那样就够了,但原生日历那奇怪且十分不友好的style,受到theme的影响,各种头疼,使用此控件,你只需要简简单单定制月视图就够了,CalendarView 能非常简单就高仿各种日历UI
CalendarView 提供了 setSchemeDate(Map
日历类 Calendar 提供了许多十分有用的API
boolean isWeekend();//判断是不是周末,可以用不同的画笔绘制周末的样式
int getWeek();//获取星期
String getSolarTerm();//获取24节气,可以用不同颜色标记不同节日
String getGregorianFestival();//获取公历节日,自由判断,把节日换上喜欢的颜色
String getTraditionFestival();//获取传统节日
boolean isLeapYear();//是否是闰年
int getLeapMonth();//获取闰月
boolean isSameMonth(Calendar calendar);//是否相同月
int compareTo(Calendar calendar);//毕竟日期大小 -1 0 1
long getTimeInMillis();//获取时间戳
int differ(Calendar calendar);//日期运算,相差多少天
<declare-styleable name="CalendarView">
<attr name="calendar_padding" format="dimension" />
<attr name="month_view" format="color" />
<attr name="week_view" format="string" />
<attr name="week_bar_height" format="dimension" />
<attr name="week_bar_view" format="color" />
<attr name="week_line_margin" format="dimension" />
<attr name="week_line_background" format="color" />
<attr name="week_background" format="color" />
<attr name="week_text_color" format="color" />
<attr name="week_text_size" format="dimension" />
<attr name="current_day_text_color" format="color" />
<attr name="current_day_lunar_text_color" format="color" />
<attr name="calendar_height" format="string" />
<attr name="day_text_size" format="string" />
<attr name="lunar_text_size" format="string" />
<attr name="scheme_text" format="string" />
<attr name="scheme_text_color" format="color" />
<attr name="scheme_month_text_color" format="color" />
<attr name="scheme_lunar_text_color" format="color" />
<attr name="scheme_theme_color" format="color" />
<attr name="selected_theme_color" format="color" />
<attr name="selected_text_color" format="color" />
<attr name="selected_lunar_text_color" format="color" />
<attr name="current_month_text_color" format="color" />
<attr name="other_month_text_color" format="color" />
<attr name="current_month_lunar_text_color" format="color" />
<attr name="other_month_lunar_text_color" format="color" />
<attr name="year_view_month_text_size" format="dimension" />
<attr name="year_view_day_text_size" format="dimension" />
<attr name="year_view_month_text_color" format="color" />
<attr name="year_view_day_text_color" format="color" />
<attr name="year_view_scheme_color" format="color" />
<attr name="min_year" format="integer" />
<attr name="max_year" format="integer" />
<attr name="min_year_month" format="integer" />
<attr name="max_year_month" format="integer" />
<attr name="month_view_scrollable" format="boolean" />
<attr name="week_view_scrollable" format="boolean" />
<attr name="year_view_scrollable" format="boolean" />
<attr name="month_view_show_mode">
<enum name="mode_all" value="0" />
<enum name="mode_only_current" value="1" />
<enum name="mode_fix" value="2" />
attr>
<attr name="week_start_with">
<enum name="sun" value="1" />
<enum name="mon" value="2" />
<enum name="sat" value="7" />
attr>
<attr name="select_mode">
<enum name="default_mode" value="0" />
<enum name="single_mode" value="1" />
<enum name="range_mode" value="2" />
attr>
<attr name="min_select_range" format="integer" />
<attr name="max_select_range" format="integer" />
declare-styleable>
https://github.com/huanghaibin-dev/CalendarView