※效果

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZ2xvbmd4aW4yNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

※用法

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而一个超级漂亮的日历控件的更多相关文章

  1. 用c/c++混合编程方式为ios/android实现一个自绘日期选择控件(一)

    本文为原创,如有转载,请注明出处:http://www.cnblogs.com/jackybu 前言 章节: 1.需求描述以及c/c++实现日期和月历的基本操作 2.ios实现自绘日期选择控件 3.a ...

  2. 推荐一款JavaScript日历控件:kimsoft-jscalendar

    一.什么是 kimsoft-jscalendar     一个简洁的avaScript日历控件,可在Java Web项目,.NET Web 项目中使用 二.kimsoft-jscalendar 有什么 ...

  3. 多功能版vue日历控件

    下载地址:https://pan.baidu.com/s/1nvpx0tB5cIvvqHuApz_MpQ 之前写了一个简单的vue日历控件:https://www.cnblogs.com/mrzhu/ ...

  4. 撸一个Android高性能日历控件,高仿魅族

    Android原生的CalendarView根本无法满足我们日常开发的需要,在开发吾记APP的过程中,我觉得需要来一款高性能且美观简洁的日历控件,觉得魅族的日历风格十分适合,于是打算撸一款. gith ...

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

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

  6. android 自定义日历控件

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

  7. android日历控件(一)

    自定义日历并且具备设置今天以前的时间不可点选,以前的颜色和当前的颜色不同,以及获取两次点击日期之间间隔的天数所以说细节比较多 个人习惯,先上图 靠,笔记本不知道怎么回事,禁用到触摸板之后 再次唤醒屏幕 ...

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

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

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

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

随机推荐

  1. 【原创】leetCodeOj --- Largest Number 解题报告

    原题地址: https://oj.leetcode.com/problems/largest-number/ 题目内容: Given a list of non negative integers, ...

  2. windows下使用lighttpd+php(fastcgi)+mysql

    一.windows下编译配置执行lighttpd 1.下载并安装cygwin. 2.下载lighttpd源码并解压3.在cygwin环境下进入lighttpd的解压文件夹后,执行: 1> ./c ...

  3. SQL查询优化——数据结构设计

    本文部分内容会涉及mysql,可能在其它数据库中并不适用. 本章节仅仅针对数据库结构设计做讨论.查询优化的其它内容待续. 数据库设计及使用是WEB开发程序猿必备的一项基础技能,在大数据量和高并发场景, ...

  4. UVA - 12338 Anti-Rhyme Pairs (哈希)

    Description D Anti-Rhyme Pairs Input: Standard Input Output: Standard Output Often two words that rh ...

  5. 有人实践过 Phabricator 以及 Arcanist 作为 code review 的工具么?(转)

    作者:覃超链接:http://www.zhihu.com/question/19977889/answer/13539702来源:知乎 平时就经常实践. 整个公司的code review就是使用这个. ...

  6. Git使用汇总

    1.下载代码,代码被下载到本地 git clone https://github.com/nuptboyzhb 2.提交代码 git commit -a -m "期间提交的信息叙述性说明&q ...

  7. Code Forces 448C Painting Fence 贪婪的递归

    略有上升称号,最近有很多问题,弥补啊,各类竞赛滥用,来不及做出了所有的冠军.这个话题 这是一个长期记忆的主题.这是不是太困难,基本技能更灵活的测试,每次我们来看看这个问题可以被删除,处理然后分段层,贪 ...

  8. 交互式命令 expect

    shell尽管很强大.但是貌似无法完成交互式命令的操作,实例 ssh host 如果host而且该机没有加入信任.手动输入的时间需要password. 这样的情况下可以使用expect支持. 下面举个 ...

  9. 为什么在Python3.4.1里输入print 10000L或10000L失败

    打开Python的命令行交互窗体,而且在里面进行以下的输入: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 ...

  10. swift类名称显示变量

    <span style="background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: Aria ...