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) 版权声明:转载注 ...
随机推荐
- Ajax.BeginForm返回方法OnSuccess
在MVC3里面——程序集 System.Web.Mvc.dll, v4.0.30319有这么一个Ajax.BeginForm异步登录验证的类型,我们在下面给出一个例子:在登录页面Logion.csht ...
- HDU 4540 威威猫系列故事——打地鼠(DP)
点我看题目 题意 :中文题,不详述. 思路 : 状态转移方程 dp[ i ][ j ] = dp[i-1][k] + fabs(a[ i ][ j ]-a[i-1][k]) ; dp[i][j]代表的 ...
- HDU4535+公式
错排公式. 用64位! /* */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...
- SpringMVC可以配置多个拦截后缀*.html和.do等
一个servlet可以配置多个servlet-mapping, 因此在xml文件中我们可以这样配置: <!-- springmvc配置 --> <servlet> <se ...
- configure脚本参数介绍
configure脚本有大量的命令行选项. 下面对每一个选项进行简略的介绍: --cache-file=FILE'configure' 会在你的系统上测试存在的特性(或者bug!).为了加速随后进行的 ...
- Android 圆角Button
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbEAAADrCAYAAADnsqiUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAA
- S3C2410 实验三——块拷贝、字拷贝(寄存器的理解)
因为笔记做在 evernote 上,博客上就不再重新敲了. http://www.evernote.com/shard/s307/sh/5bd591a1-dbbd-4457-812a-17c08c22 ...
- Android 完全退出程序,以及再按一次返回键退出程序
再按一次返回键退出最终完整方案: boolean isExit; @Override protected void onCreate(Bundle savedInstanceState) { ...
- Android开发之异步消息处理机制AsyncTask
转自:Android AsyncTask完全解析,带你从源码的角度彻底理解 另外一篇比较详细的博文:http://blog.csdn.net/liuhe688/article/details/6532 ...
- bzoj2763
首先是稀疏图,不难想到dij+heap 观察题目可以知道,0<=k<=10; 所以比较裸的想法就是,d[i,j]表示已经免费了i条线路后到达j的最短路 容易得到 d[i,j]:=min(d ...