Android史上功能最全的日历控件
※效果
※用法
package com.fancyy.calendarweight; import java.util.ArrayList;
import java.util.List; import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView; import com.fancyy.calendarweight.KCalendar.OnCalendarClickListener;
import com.fancyy.calendarweight.KCalendar.OnCalendarDateChangedListener; public class MainActivity extends Activity { String date = null;// 设置默认选中的日期 格式为 “2014-04-05” 标准DATE格式 Button bt; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new PopupWindows(MainActivity.this, bt);
}
});
} public class PopupWindows extends PopupWindow { public PopupWindows(Context mContext, View parent) { View view = View.inflate(mContext, R.layout.popupwindow_calendar,
null);
view.startAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.fade_in));
LinearLayout ll_popup = (LinearLayout) view
.findViewById(R.id.ll_popup);
ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.push_bottom_in_1)); setWidth(LayoutParams.FILL_PARENT);
setHeight(LayoutParams.FILL_PARENT);
setBackgroundDrawable(new BitmapDrawable());
setFocusable(true);
setOutsideTouchable(true);
setContentView(view);
showAtLocation(parent, Gravity.BOTTOM, 0, 0);
update(); final TextView popupwindow_calendar_month = (TextView) view
.findViewById(R.id.popupwindow_calendar_month);
final KCalendar calendar = (KCalendar) view
.findViewById(R.id.popupwindow_calendar);
Button popupwindow_calendar_bt_enter = (Button) view
.findViewById(R.id.popupwindow_calendar_bt_enter); popupwindow_calendar_month.setText(calendar.getCalendarYear() + "年"
+ calendar.getCalendarMonth() + "月"); if (null != date) { int years = Integer.parseInt(date.substring(0,
date.indexOf("-")));
int month = Integer.parseInt(date.substring(
date.indexOf("-") + 1, date.lastIndexOf("-")));
popupwindow_calendar_month.setText(years + "年" + month + "月"); calendar.showCalendar(years, month);
calendar.setCalendarDayBgColor(date,
R.drawable.calendar_date_focused);
} List<String> list = new ArrayList<String>(); //设置标记列表
list.add("2014-04-01");
list.add("2014-04-02");
calendar.addMarks(list, 0); //监听所选中的日期
calendar.setOnCalendarClickListener(new OnCalendarClickListener() { public void onCalendarClick(int row, int col, String dateFormat) {
int month = Integer.parseInt(dateFormat.substring(
dateFormat.indexOf("-") + 1,
dateFormat.lastIndexOf("-"))); if (calendar.getCalendarMonth() - month == 1//跨年跳转
|| calendar.getCalendarMonth() - month == -11) {
calendar.lastMonth(); } else if (month - calendar.getCalendarMonth() == 1 //跨年跳转
|| month - calendar.getCalendarMonth() == -11) {
calendar.nextMonth(); } else {
calendar.removeAllBgColor();
calendar.setCalendarDayBgColor(dateFormat,
R.drawable.calendar_date_focused);
date = dateFormat;//最后返回给全局 date
}
}
}); //监听当前月份
calendar.setOnCalendarDateChangedListener(new OnCalendarDateChangedListener() {
public void onCalendarDateChanged(int year, int month) {
popupwindow_calendar_month
.setText(year + "年" + month + "月");
}
}); //上月监听button
RelativeLayout popupwindow_calendar_last_month = (RelativeLayout) view
.findViewById(R.id.popupwindow_calendar_last_month);
popupwindow_calendar_last_month
.setOnClickListener(new OnClickListener() { public void onClick(View v) {
calendar.lastMonth();
} }); //下月监听button
RelativeLayout popupwindow_calendar_next_month = (RelativeLayout) view
.findViewById(R.id.popupwindow_calendar_next_month);
popupwindow_calendar_next_month
.setOnClickListener(new OnClickListener() { public void onClick(View v) {
calendar.nextMonth();
}
}); //关闭窗体
popupwindow_calendar_bt_enter
.setOnClickListener(new OnClickListener() { public void onClick(View v) {
dismiss();
}
});
}
} }
※Demo下载
Android史上功能最全的日历控件的更多相关文章
- Android自定义View(CustomCalendar-定制日历控件)
转载请标明出处: http://blog.csdn.net/xmxkf/article/details/54020386 本文出自:[openXu的博客] 目录: 1分析 2自定义属性 3onMeas ...
- 在iOS上实现一个简单的日历控件
http://blog.csdn.net/jasonblog/article/details/21977481 近期需要写一个交互有点DT的日历控件,具体交互细节这里略过不表. 不过再怎么复杂的控件, ...
- Android自己定义组件之日历控件-精美日历实现(内容、样式可扩展)
需求 我们知道.Android系统本身有自带的日历控件,网络上也有非常多开源的日历控件资源.可是这些日历控件往往样式较单一.API较多.不易于在实际项目中扩展并实现出符合详细样式风格的,内容可定制的效 ...
- Android开发中几种有用的的日历控件实现
我们大家都知道,在Android平台3.0中才新增了日历视图控件,可以显示网格状的日历内容,那么对于3.0以下的版本要使用日历控件只能借助第三方,目前用的最多的是CalendarView. 先简单介绍 ...
- vue日历控件,自定义选择年月 选择年月日 选择年月日时 选择年月日时分,自定义日期范围
下载地址:https://pan.baidu.com/s/1iEZl4kDkEg4ybwqc7aI7vQ 注:功能更加全面的日历控件请访问:https://www.cnblogs.com/mrzhu/ ...
- 强烈推荐:Android史上最强大的自定义任务软件Tasker
强烈推荐:Android史上最强大的自定义任务软件Taskerhttp://bbs.mumayi.com/thread-28387-1-1.html(出处: 木蚂蚁手机乐园) Android上的Tas ...
- android 自定义日历控件
日历控件View: /** * 日历控件 功能:获得点选的日期区间 * */ public class CalendarView extends View implements View.OnTouc ...
- Android 一个日历控件的实现代码
转载 2017-05-19 作者:Othershe 我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...
- Android自定义控件之日历控件
标签: android 控件 日历 应用 需求 2015年09月26日 22:21:54 25062人阅读 评论(109) 收藏 举报 分类: Android自定义控件系列(7) 版权声明:转载注 ...
随机推荐
- java super 隐式参数
第41集 所有构造器里,第一句话就是super() (隐式的,系统自动执行) 鸟构造器调用动物构造器,动物构造器调用object构造器. (系统默认的) tostring() 方法 ...
- Delphi GDI+ Library
GDI+ LibraryThis library enables GDI+ functionality for Delphi 2009 and later. It differs from other ...
- 点点滴滴-NET下的常用框架
刘冬的博客:http://www.cnblogs.com/GoodHelper/category/214139.html (Spring.net和Nhibernate) Kyo-yo : http: ...
- c while 循环
c代码: #include <stdio.h> int main(void){ unsigned long sum=1UL; unsigned int j=1U; unsigned ; p ...
- PLSQL操作
游标 SQL> set serveroutput onSQL> DECLARE 2 --定义游标,因为该游标中的数据需要更新,所以使用for update 3 CURSOR ...
- ODBC具体使用
应用程序 应用程序对外提供使用者交谈界面,同时对内执行资料之准备工作数据库系统所传回来的结果在显示给使用者看.简单来说,应用程序即ODBC 界面执行下列主要工作:1. Request a connec ...
- AS 学习笔记 加载数据
AS2 加载本地(外部)数据.swf .png .jpg 等资源使用loadMovie() 加载库里面的mc 用 attachMovie AS3 加载本地(外部)数据 用 Loader 类来完成这个操 ...
- css3动画(transition)属性探讨
在webapp引用开发中经常会用到css3动画效果,下面我们就一起探讨一下这个属性的使用. 在哪里定义动画效果? css3动画一般通过鼠标事件或者说状态定义动画,通常我们可以用CSS中伪类和js中的鼠 ...
- 物联网操作系统HelloX V1.77(beta)版本发布
物联网操作系统HelloX V1.77发布 经过近半年的努力,物联网操作系统HelloX V1.77版本正式完成,源代码已上载到github(github.com/hellox-project/Hel ...
- 【转】Windows7打造全方位护眼系统
原文网址:http://www.cnblogs.com/duboway/archive/2013/04/20/3033257.html 电脑屏幕: Win7和Vista系统设置如下: 第一步:桌面空白 ...