android 日历 周显示,按周显示的日历和按月显示的日历,你需要吗
周日历
使用
布局:
android:id="@+id/week_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:wc_headerBgColor="#ccc"
app:wc_headerHeight="60dp"
app:wc_calendarHeight="55dp" />
代码中:
设置布局显示
必须调用setGetViewHelper方法加载布局,getDayView方法控制每一天显示,
getWeekView方法控制星期显示,使用类似ListView中BaseAdapter中的getView方法。
weekCalendar.setGetViewHelper(new GetViewHelper() {
@Override
public View getDayView(int position, View convertView, ViewGroup parent, DateTime dateTime, boolean select) {
if(convertView == null){
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_day, parent, false);
}
TextView tvDay = (TextView) convertView.findViewById(R.id.tv_day);
tvDay.setText(dateTime.toString("d"));
if(CalendarUtil.isToday(dateTime) && select){
tvDay.setTextColor(Color.WHITE);
tvDay.setBackgroundResource(R.drawable.circular_blue);
} else if(CalendarUtil.isToday(dateTime)){
tvDay.setTextColor(getResources().getColor(R.color.colorTodayText));
tvDay.setBackgroundColor(Color.TRANSPARENT);
} else if(select){
tvDay.setTextColor(Color.WHITE);
tvDay.setBackgroundResource(R.drawable.circular_blue);
} else {
tvDay.setTextColor(Color.BLACK);
tvDay.setBackgroundColor(Color.TRANSPARENT);
}
ImageView ivPoint = (ImageView) convertView.findViewById(R.id.iv_point);
ivPoint.setVisibility(View.GONE);
for (DateTime d : eventDates) {
if(CalendarUtil.isSameDay(d, dateTime)){
ivPoint.setVisibility(View.VISIBLE);
break;
}
}
return convertView;
}
@Override
public View getWeekView(int position, View convertView, ViewGroup parent, String week) {
if(convertView == null){
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_week, parent, false);
}
TextView tvWeek = (TextView) convertView.findViewById(R.id.tv_week);
tvWeek.setText(week);
if(position == 0 || position == 6){
tvWeek.setTextColor(getResources().getColor(R.color.colorAccent));
}
return convertView;
}
});
设置日期选择监听
weekCalendar.setDateSelectListener(new DateSelectListener() {
@Override
public void onDateSelect(DateTime selectDate) {
String text = "你选择的日期是:" + selectDate.toString("yyyy-MM-dd");
tvSelectDate.setText(text);
}
});
设置周变化监听
weekCalendar.setWeekChangedListener(new WeekChangeListener() {
@Override
public void onWeekChanged(DateTime firstDayOfWeek) {
String text = "本周第一天:" + firstDayOfWeek.toString("yyyy年M月d日")
+ ",本周最后一天:" + new DateTime(firstDayOfWeek).plusDays(6).toString("yyyy年M月d日");
tvWeekChange.setText(text);
}
});
其他方法
getSelectDateTime 获取当前选中日期
setSelectDateTime(DateTime dateTime) 设置选中日期
gotoDate(DateTime dateTime) 跳转到指定日期
getCurrentFirstDay 获取当前页面第一天
refresh 刷新界面
月日历
使用
布局:
android:id="@+id/month_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
app:mc_calendarHeight="@dimen/calender_content_height"/>
代码中:
设置布局显示
必须调用setGetViewHelper方法加载布局,getDayView方法控制每一天显示,
getWeekView方法控制星期显示,使用类似ListView中BaseAdapter中的getView方法。
monthCalendar.setGetViewHelper(new GetViewHelper() {
@Override
public View getDayView(int position, View convertView, ViewGroup parent, Day day) {
if(convertView == null){
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_day, parent, false);
}
TextView tvDay = (TextView) convertView.findViewById(R.id.tv_day);
DateTime dateTime = day.getDateTime();
tvDay.setText(dateTime.toString("d"));
boolean select = day.isSelect();
if(CalendarUtil.isToday(dateTime) && select){
tvDay.setTextColor(Color.WHITE);
tvDay.setBackgroundResource(R.drawable.circular_blue);
} else if(CalendarUtil.isToday(dateTime)){
tvDay.setTextColor(getResources().getColor(R.color.colorTodayText));
tvDay.setBackgroundColor(Color.TRANSPARENT);
} else if(select){
tvDay.setTextColor(Color.WHITE);
tvDay.setBackgroundResource(R.drawable.circular_blue);
} else {
tvDay.setBackgroundColor(Color.TRANSPARENT);
if(day.isOtherMonth()){
tvDay.setTextColor(Color.LTGRAY);
} else {
tvDay.setTextColor(Color.BLACK);
}
}
ImageView ivPoint = (ImageView) convertView.findViewById(R.id.iv_point);
ivPoint.setVisibility(View.INVISIBLE);
for (DateTime d : eventDates) {
if(CalendarUtil.isSameDay(d, dateTime)){
ivPoint.setVisibility(View.VISIBLE);
break;
}
}
return convertView;
}
@Override
public View getWeekView(int position, View convertView, ViewGroup parent, String week) {
if(convertView == null){
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_week, parent, false);
}
TextView tvWeek = (TextView) convertView.findViewById(R.id.tv_week);
switch (position){
case 0:
week = "日";
tvWeek.setTextColor(getResources().getColor(R.color.colorAccent));
break;
case 1:
week = "一";
break;
case 2:
week = "二";
break;
case 3:
week = "三";
break;
case 4:
week = "四";
break;
case 5:
week = "五";
break;
case 6:
week = "六";
tvWeek.setTextColor(getResources().getColor(R.color.colorAccent));
break;
}
tvWeek.setText(week);
return convertView;
}
});
设置日期选择监听
monthCalendar.setOnDateSelectListener(new OnDateSelectListener() {
@Override
public void onDateSelect(DateTime selectDate) {
tvSelectDate.setText("你选择的日期:" + selectDate.toString("yyyy-MM-dd"));
}
});
设置月切换监听
monthCalendar.setOnMonthChangeListener(new OnMonthChangeListener() {
@Override
public void onMonthChanged(int currentYear, int currentMonth) {
tvMonthChange.setText(currentYear + "年" + currentMonth + "月");
}
});
其他方法
getSelectDateTime 获取当前选中日期
setSelectDateTime(DateTime dateTime) 设置选中日期
gotoDate(DateTime dateTime) 跳转到指定日期
getCurrentYear 获取当前显示年份
getCurrentMonth 获取当前显示月份
refresh 刷新界面
补充
两个日历设计类似,使用基本相同,时间使用的是jodatime。
android 日历 周显示,按周显示的日历和按月显示的日历,你需要吗相关推荐
- 如何在outlook里显示自然周的周数
一年有52周,我们如何在outlook里方便的查看自然周的序号呢?比如2019年11月25日到29日是2019年的第几周?outlook默认是没有显示这个序号的. option设置里,打开Calend ...
- 【仿微信朋友圈时间,几天前,几分钟前,显示几周前】
先说js文件 每个方法显示的不一样,有显示几天前,几分钟几小时前的,有显示几周前的,看着调用 let time = {timeconvert(event) {// const enventTime = ...
- Win11时间怎么显示星期几?Win11怎么显示今天周几?
Win11时间怎么显示星期几?Win11怎么显示今天周几?很多朋友希望Win11右下角时间能够显示今天是星期几,因为有时候临近周末感觉会比较开心,那么具体应该如何设置呢? 这里有更简单的电脑怎么重装 ...
- 基于Vue的小日历(支持按周切换)
基于Vue的日历小功能,可根据实际开发情况按每年.每月.每周.进行切换 <template><div class="date"><!-- 年份 月份 ...
- vue日历,可以按周、月切换
仿钉钉的日历,可以实现周.月切换,代码是在另一位大神那里参考修改的,感谢https://blog.csdn.net/x_xiaoqi/article/details/79142055#commentB ...
- android实现箭头流程列表_Android开发关于ExpandableListView上下箭头左右显示的笔记...
释放双眼,带上耳机,听听看~! 关键属性: android:layoutDirection="" 当安卓的layoutDirection = "rtl" 时,箭 ...
- android 如何从服务器端的数据库中拿数据,在客户端显示类?
============问题描述============ android 如何从服务器端的数据库中拿数据,在客户端显示类? ============解决方案1============ 写一个网络访问的 ...
- android 卫星地图,推荐一款亲测好用,可显示卫星地图,高斯平面直角坐标和计算图幅编号等功能的安卓定位导航软件~...
推荐一款亲测好用,可显示卫星地图,高斯平面直角坐标和计算图幅编号等功能的安卓定位导航软件-步行者坐标导航. 一.软件下载 小米应用商店搜:步行者坐标导航或 http://appcdn.wapx.cn/ ...
- 【Android SDM660源码分析】- 03 - UEFI XBL GraphicsOutput BMP图片显示流程
[Android SDM660源码分析]- 03 - UEFI XBL GraphicsOutput BMP图片显示流程 1. GraphicsOutput.h 2. 显示驱动初化 DisplayDx ...
最新文章
- 完美:C# Blazor中显示Markdown并添加代码高亮
- PAT乙类之1011 A+B 和 C
- error C2220: 警告被视为错误 - 没有生成“object”文件
- java集合转labelpoint_java – 向Spark ML LabeldPoint添加自定义字段
- [APIO2009]抢掠计划
- MATLAB图形界面设计(上)
- HDU2020 绝对值排序【排序】
- Python:学习笔记(一)
- 详细版【卷积神经网络CNN】基础模型(邱锡鹏)
- 【Paper】2015_Coordinated cruise control for high-speed train movements based on a multi-agent model
- FTP原理和修改FTP默认端口
- 网络子系统34_网桥设备的传输与接收
- 同一个jar包不同版本冲突解决方法
- esxi安装威联通_威联通TS-453Bmini NAS加装内存,轻松玩转虚拟机安装win10系统
- 2022-2028年全球及中国汽车保险丝行业投资前景分析
- javac错误:javac不是内部或外部命令 也不是可运行的程序 解决方法
- vue实现打开新窗口预览PDF文件
- 图解MySQL在Linux下的安装与配置
- 华生详解万科董事会:我为什么不支持大股东意见(中)
- 图扑软件助力企业数字化转型