Android自带CalendarView类实现日历视图
文章由来:学习一下日历控件的实现,Android3.0以下的版本请查阅其他文章。
本文主要是介绍Android日历视图控件CalendarView相关的内容,然后在后面会给出一个简单的Demo。
CalendarView继承自FrameLayout
其他文章都引用的类似的java代码示例如下:
public class MainActivity extends Activity implements OnClickListener,
OnDateChangeListener { private CalendarView calendarView;
private TextView tvCalendar, tvReminder, tvNote, tvMore;
private ImageView ivNext;
private ImageView ivPrevious; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); // initData();
// initUI();
}
}
这部分代码的工作主要在于加载layout,CalendarView被使用的时候有一些默认值,这里对默认值做了一点点改动,对界面进行美化。
xml代码中CalendarView部分如下:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="8"
android:orientation="vertical" > <CalendarView
android:id="@+id/calendarview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:focusedMonthDateColor="@color/whitesmoke"
android:unfocusedMonthDateColor="@color/transparent"
android:selectedWeekBackgroundColor="@color/transparent"
android:showWeekNumber="false"
android:weekSeparatorLineColor="@color/transparent" />
</LinearLayout>
实现的效果图是这样的:

以上代码就引出了使用到了CalendarView类的属性设置,看看在设置是用得较多的代码:
| 公有方法 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| getDate()
Gets the selected date in milliseconds since January 1, 1970 00:00:00 in
getDefault() time zone. |
|||||||||||
| getDateTextAppearance()
Gets the text appearance for the calendar dates.
|
|||||||||||
| getFirstDayOfWeek()
Gets the first day of week.
|
|||||||||||
| getFocusedMonthDateColor()
Gets the color for the dates in the focused month.
|
|||||||||||
| getMaxDate()
Gets the maximal date supported by this
CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone. |
|||||||||||
| getMinDate()
Gets the minimal date supported by this
CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone. |
|||||||||||
| getSelectedDateVerticalBar()
Gets the drawable for the vertical bar shown at the beginning and at the end of the selected date.
|
|||||||||||
| getSelectedWeekBackgroundColor()
Gets the background color for the selected week.
|
|||||||||||
| getShowWeekNumber()
Gets whether to show the week number.
|
|||||||||||
| getShownWeekCount()
Gets the number of weeks to be shown.
|
|||||||||||
| getUnfocusedMonthDateColor()
Gets the color for the dates in a not focused month.
|
|||||||||||
| getWeekDayTextAppearance()
Gets the text appearance for the week day abbreviation of the calendar header.
|
|||||||||||
| getWeekNumberColor()
Gets the color for the week numbers.
|
|||||||||||
| getWeekSeparatorLineColor()
Gets the color for the separator line between weeks.
|
|||||||||||
| isEnabled()
返回该视图的活性状态.由子类来解释各自的活性状态.
|
|||||||||||
| onInitializeAccessibilityEvent(AccessibilityEvent event)
使用作为事件源的该视图的信息初始化
AccessibilityEvent 事件.换句话说, 该视图状态的变化是触发辅助事件的源头. |
|||||||||||
| onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
使用该视图的信息初始化
AccessibilityNodeInfo 对象. |
|||||||||||
| setDate(long date)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in
getDefault() time zone. |
|||||||||||
| setDate(long date, boolean animate, boolean center)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in
getDefault() time zone. |
|||||||||||
| setDateTextAppearance(int resourceId)
Sets the text appearance for the calendar dates.
|
|||||||||||
| setEnabled(boolean enabled)
设置视图的可用状态.由子类决定视图的各可用状态如何显示.
|
|||||||||||
| setFirstDayOfWeek(int firstDayOfWeek)
Sets the first day of week.
|
|||||||||||
| setFocusedMonthDateColor(int color)
Sets the color for the dates of the focused month.
|
|||||||||||
| setMaxDate(long maxDate)
Sets the maximal date supported by this
CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone. |
|||||||||||
| setMinDate(long minDate)
Sets the minimal date supported by this
CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone. |
|||||||||||
| setOnDateChangeListener(CalendarView.OnDateChangeListener listener)
Sets the listener to be notified upon selected date change.
|
|||||||||||
| setSelectedDateVerticalBar(Drawable drawable)
Sets the drawable for the vertical bar shown at the beginning and at the end of the selected date.
|
|||||||||||
| setSelectedDateVerticalBar(int resourceId)
Sets the drawable for the vertical bar shown at the beginning and at the end of the selected date.
|
|||||||||||
| setSelectedWeekBackgroundColor(int color)
Sets the background color for the selected week.
|
|||||||||||
| setShowWeekNumber(boolean showWeekNumber)
Sets whether to show the week number.
|
|||||||||||
| setShownWeekCount(int count)
Sets the number of weeks to be shown.
|
|||||||||||
| setUnfocusedMonthDateColor(int color)
Sets the color for the dates of a not focused month.
|
|||||||||||
| setWeekDayTextAppearance(int resourceId)
Sets the text appearance for the week day abbreviation of the calendar header.
|
|||||||||||
| setWeekNumberColor(int color)
Sets the color for the week numbers.
|
|||||||||||
| setWeekSeparatorLineColor(int color)
Sets the color for the separator line between weeks.
|
|||||||||||
一般常用的方法摘借(非本人翻译,感谢翻译的朋友们):
long getDate(); //获取从1970年,1月1日,0点0分0秒到现在的毫秒数,因为返回是long型最终只能截止到2038年
int getFirstDayOfWeek(); //获取当天是本周的第几天,Android123提示返回的定义在java.util.Calendar类中,比如Calendar.Monday为星期一,定义值为2。
long getMaxDate(); //获取CalendarView支持1970年到那天的最大天数
long getMinDate(); //获取CalendarView支持1970年到那天的最小天数
boolean getShowWeekNumber(); //获取是否显示星期号
boolean isEnabled(); //是否显示本日历视图
public void setDate(long date, boolean animate, boolean center); //设置选择日期到1970年的描述
void setDate(long date); //设置选择的日期描述到1970年
void setEnabled(boolean enabled); //设置是否启用视图
void setFirstDayOfWeek(int firstDayOfWeek); //设置本周起始天数
void setMaxDate(long maxDate);
void setMinDate(long minDate);
void setOnDateChangeListener(CalendarView.OnDateChangeListener listener); //日历视图修改的接口,这个介绍看下面。
void setShowWeekNumber(boolean showWeekNumber); //设置是否显示周号
如果有了解更多,继续补充在这里
Android自带CalendarView类实现日历视图的更多相关文章
- Android学习笔记(27):日历视图Calendar
日历视图CalendarView可用于显示和选择日期. 能够调用setOnDateChangedListener()方法绑定事件监听器. 经常使用XML属性和相关方法: XML属性 相关方法 说明 a ...
- Android零基础入门第60节:日历视图CalendarView和定时器Chronometer
原文:Android零基础入门第60节:日历视图CalendarView和定时器Chronometer 上一期学习了AnalogClock.DigitalClock和TextClock时钟组件,本期继 ...
- Android日历视图(CalendarView)讲解-android学习之旅(三十六)
CalendarView简介 CalendarView用于显示和选择日期,如果希望监听事件的改变可以用setOnDateChangeListener()方法. CalendarView属性介绍 代码示 ...
- Android 日历视图(Calendarview)
1.介绍 2.常用属性 3.xml文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayou ...
- 日历视图(CalendarView)组件的功能和用法
日历视图(CalendarView)可用于显示和选择日期,用户既可选择一个日期,也可通过触摸来滚动日历.如果希望监控该组件的日历改变,可调用CalendarView的setOnDateChangeLi ...
- 日历视图(CalendarView)
日历视图(Calendarview) 常用属性: android:selectedWeekBackgroundColor(设置被选中周的背景颜色) android:showWeekNumber(设置是 ...
- 调用Android自带日历功能(日历列表单、添加一个日历事件)
调用Android自带日历功能 觉得这篇文章不错,转载过来. 转载:http://blog.csdn.net/djy1992/article/details/9948393 Android手机配备有 ...
- ios日历视图实现日期输入
在视图控制器上,触摸textfield,打开的不是虚拟键盘,也不是datepicker,也不要actionsheet,要一个类似html上的日历输入框. 这类控件有很多开源的,但目标不是我想要的.参考 ...
- Expo大作战(二十七)--expo sdk api之Util(expo自带工具类),tackSnapshotAsync,Svg,SQLite
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
随机推荐
- Project Euler 81:Path sum: two ways 路径和:两个方向
Path sum: two ways In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom ...
- Codeforces D546:Soldier and Number Game
题目链接 输入t对数 a, b 求(b,a]内的每个数拆成素因子的个数和 这里每个数都可以写成素数的乘积,可以写成几个素数的和就有几个素因子,这里求的是(b,a]内的素因子和 思路: 素数的素因子个数 ...
- JAVA:23种设计模式详解(转)
设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- NET Remoting 示例
.NET Remoting是.NET平台上允许存在于不同应用程序域中的对象相互知晓对方并进行通讯的基础设施.调用对象被称为客户端,而被调用对象则被称为服务器或者服务器对象.简而言之,它就是.NET平台 ...
- 基于SimHash的微博去重
一.需求:对微博数据进行去重,数据量比较小,几十万条左右. 二.解决方案 1.采用SimHash的指纹信息去重方法. 三.实现方案 1.对每一条微博使用tf-idf与特征词 2.使用每条微博的特征词, ...
- 面向对象设计Object Oriented Design
http://www.codeproject.com/Articles/93369/How-I-explained-OOD-to-my-wife http://www.cnblogs.com/niyw ...
- Java中静态代码块,代码块,构造方法优先级、区别及代码示例
在项目中遇到了代码块的知识点,跑了下测试,写下结论 代码优先级:静态代码块 -> 构造代码块 -> 构造方法 多个代码块优先级,按照“先定义的代码先执行,后定义的代码后执行”原则执行 静态 ...
- Redis系列文章导读
1. Redis简介 1.1 Redis VS Memcached 2. Redis安装教程 3. Redis数据类型 4. Redis常用命令 4.1 key 4.2 string 4.3 hash ...
- Struts2注解配置之@Namespace(四)
今天开始学习@Namespace注解. 还是先看一段代码: package com.example.actions; import org.apache.struts2.convention.anno ...
- treap完全版模板
这是我综合poj1442 3481 2352的treap操作 得到treap完全版模板.(经测AC) 结构体Tree { int key; //键值 int size; //该子树总节点个数 int ...