※效果




※用法

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下载

http://download.csdn.net/detail/u010785585/8016687


Android史上功能最全的日历控件的更多相关文章

  1. Android自定义View(CustomCalendar-定制日历控件)

    转载请标明出处: http://blog.csdn.net/xmxkf/article/details/54020386 本文出自:[openXu的博客] 目录: 1分析 2自定义属性 3onMeas ...

  2. 在iOS上实现一个简单的日历控件

    http://blog.csdn.net/jasonblog/article/details/21977481 近期需要写一个交互有点DT的日历控件,具体交互细节这里略过不表. 不过再怎么复杂的控件, ...

  3. Android自己定义组件之日历控件-精美日历实现(内容、样式可扩展)

    需求 我们知道.Android系统本身有自带的日历控件,网络上也有非常多开源的日历控件资源.可是这些日历控件往往样式较单一.API较多.不易于在实际项目中扩展并实现出符合详细样式风格的,内容可定制的效 ...

  4. Android开发中几种有用的的日历控件实现

    我们大家都知道,在Android平台3.0中才新增了日历视图控件,可以显示网格状的日历内容,那么对于3.0以下的版本要使用日历控件只能借助第三方,目前用的最多的是CalendarView. 先简单介绍 ...

  5. vue日历控件,自定义选择年月 选择年月日 选择年月日时 选择年月日时分,自定义日期范围

    下载地址:https://pan.baidu.com/s/1iEZl4kDkEg4ybwqc7aI7vQ 注:功能更加全面的日历控件请访问:https://www.cnblogs.com/mrzhu/ ...

  6. 强烈推荐:Android史上最强大的自定义任务软件Tasker

    强烈推荐:Android史上最强大的自定义任务软件Taskerhttp://bbs.mumayi.com/thread-28387-1-1.html(出处: 木蚂蚁手机乐园) Android上的Tas ...

  7. android 自定义日历控件

    日历控件View: /** * 日历控件 功能:获得点选的日期区间 * */ public class CalendarView extends View implements View.OnTouc ...

  8. Android 一个日历控件的实现代码

    转载  2017-05-19   作者:Othershe   我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...

  9. Android自定义控件之日历控件

      标签: android 控件 日历 应用 需求 2015年09月26日 22:21:54 25062人阅读 评论(109) 收藏 举报 分类: Android自定义控件系列(7) 版权声明:转载注 ...

随机推荐

  1. UIWebView 与 JS 交互(1):Objective-C 调用 Javascript

    众所周知,随着硬件水平的发展,HTML5 与原生 APP 性能差距不断缩小,正在互联网科技领域扮演者越来越重要的角色.作为一种能很大程度上节约成本的技术方案,通过 HTML5 及 JS 实现的跨平台技 ...

  2. DataTable转换List<T>集合的方法

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data; ...

  3. jmeter linux使用经验小结

    1. 确认务必安装了JDK,并且把路径配置OK.否则执行会报错. 2. 当做负载机时,在hosts 配置上    你的ip   你的hostname  或者使用./bin/jmeter-server ...

  4. 如何在Oracle11中配置st_shapelib

  5. 判断微信内置浏览器的UserAgent

    要区分用户是通过"微信内置浏览器"还是"原生浏览器"打开的WebApp, 可以通过navigator.userAgent来进行判断. 以下是对各种平台上微信内置 ...

  6. IEHelper - Internet Explorer Helper Class

    http://www.codeproject.com/Articles/4411/IEHelper-Internet-Explorer-Helper-Class Discussions (81) IE ...

  7. DP录 (更新)

    补补弱项 全面发展.. 从最基础来 sdut1299最长上升子序 #include <iostream> #include<cstdio> #include<cstrin ...

  8. hadoop2.2编程:MRUnit——Test MaxTemperatureMapper

    继承关系1 1. java.lang.Object |__ org.apache.hadoop.mapreduce.JobContext |__org.apache.hadoop.mapreduce. ...

  9. cgi ISAP sapi等

    1.CGI和FastCGI是apache处理php脚本的其中两种工作模式,还有ISAPI,SAPI等 2.而php-fpm并不是一种工作模式,而是一个PHP在FastCGI模式运行下的进程管理器,全称 ...

  10. 使用 Azure Site Recovery 将内部部署虚拟化工作负荷迁移至 Azure

    ABHISHEK A. HEMRAJANI 云 + Enterprise 项目经理 我们最近发布了微软的灾难恢复即服务 (DRaaS) 产品的预览版 - Azure SiteRecovery.此产 ...