※效果




※用法

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. POJ 3308 Paratroopers(最小割EK)

    题目链接 题意 : 有一个n*m的矩阵,L个伞兵可能落在某些点上,这些点的坐标已知,需要在某些位置安上一些枪,然后每个枪可以将一行或者一列的伞兵击毙.把这种枪安装到不同行的行首.或者不同列的列首,费用 ...

  2. 【无聊放个模板系列】POJ2752 EXKMP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...

  3. UVA 11090 Going in Cycle!!

    要求给定的图的中平均权值最小的环,注意处理自环的情况就能过了. 按照w1+w2+w3+….wn < n*ave的不等式,也就是(w1-ave) + (w2-ave) +…..(wn-ave) & ...

  4. SQL Server 行列转换

    /* 标题:普通行列转换(version 2.0) 作者:范中磊 说明:普通行列转换(version 1.0)仅针对sql server 2000提供静态和动态写法,version 2.0增加sql ...

  5. asp.net中GridView的CheckedUnBindCheckBox属性

    1. 获取GridView中CheckBox所选行的字段,即使是在绑定了数据源的时候,也可以获取选中的CheckedUnBindCheckBox对应的各个列的字段 使用时根据实际情况适当的修改即可. ...

  6. ANDROID_MARS学习笔记_S01原始版_011_XML

    一.代码 1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  7. Using FireMonkey Layouts

    FireMonkey has many layout controls to choose from. Come learn the differences and how to use them t ...

  8. Android 风格化的 Toggle Buttons

    Android到默认UI比iOS到默认UI在美观程度上还是有一定到差距的,我们希望能够美化UI,并且替换掉系统默认的UI风格,使得程序在使用这些UI的时候都默认使用我们自定义到UI.本文以Toggle ...

  9. 点点滴滴-ConfigurationManager.AppSettings

    在写程序的配置文件,里面添加了几个配置,下面是appSettings节点的设置 <appSettings> <add key="StyleFolder" valu ...

  10. 用APP赚钱(转)

    英文原文:MAKING MONEY ON APPS 做为半个 iOS 开发的一家公司,我时不时地考虑如何用 APP 赚钱.最近由Brent Simmons 和 Jared Sinclair 的文章挑起 ...