效果

Android又一个超漂亮的日历控件_第1张图片

※使用方法

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 list = new ArrayList(); //设置标记列表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 + "月");}});//上月监听按钮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();}});//下月监听按钮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/7667921



更多相关文章

  1. android的一款日期选择控件
  2. Android 点击按钮,文本文字改变
  3. android 监听系统时区变化,日期变化,时间变化
  4. 转化为当前的日期和时间
  5. android简单的日期时间选择器
  6. android 添加桌面窗口小部件(托至桌面需要点击按钮才能生成的)
  7. Android动态生成按钮样式
  8. Android为按钮添加相应事件的代码
  9. 给按钮设置点击变色

随机推荐

  1. [置顶] android IPC通信(下)-AIDL
  2. TextView的跑马灯效果,还有焦点问题
  3. SuperMap iMobile for Android定位实现
  4. 关于Android的极光推送的消息栏
  5. RecyclerView不显示问题
  6. Android中的Grid间距(Grid Spacing on And
  7. 《Android开发艺术探索》笔记(五)
  8. android学习笔记之十一数据存储(Shared P
  9. androidP 系统集成时发现部分应用初次打
  10. android 实用的开源框架