源码|实用日历控件

移动开发
自己改造的实用的日历控件,pop效果,附带动画。

源码简介:自己改造的实用的日历控件,pop效果,附带动画。

下载地址:http://down.51cto.com/data/2194851

源码效果:

源码片段:

  1. public static synchronized PopCalendar getInstance(Context context, View parent, int gravity, OnCellClickListener onClickdate, 
  2.             OnClickListener onConfirm, OnDismissListener onDismiss) { 
  3.         if (gravity != -1) { 
  4.             GRAVITY_FOR_POP = gravity; 
  5.         } 
  6.         if (context == null) { 
  7.             return null
  8.         } 
  9.         if (parent == null) { 
  10.             return null
  11.         } 
  12.   
  13.         if (null == instance) { 
  14.             View view = LayoutInflater.from(context).inflate(R.layout.layout_calendar, null); 
  15.             mViewPager = (ViewPager) view.findViewById(R.id.activity_user_calendar_Viewpager); 
  16.             preImgBtn = (ImageButton) view.findViewById(R.id.activity_user_calendar_PreMonthBtn); 
  17.             nextImgBtn = (ImageButton) view.findViewById(R.id.activity_user_calendar_NextMonthBtn); 
  18.             slide_time = (TextView) view.findViewById(R.id.slide_time); 
  19.             TextView btn_confirm = (TextView) view.findViewById(R.id.tv_confirm); 
  20.             // 下面是两种方法得到宽度和高度 getWindow().getDecorView().getWidth() 
  21.             instance = new PopCalendar(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, parent); 
  22.   
  23.             final OnCellClickListener listener = onClickdate; 
  24.   
  25.             preImgBtn.setOnClickListener(new View.OnClickListener() { 
  26.   
  27.                 @Override 
  28.                 public void onClick(View v) { 
  29.                     mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1); 
  30.                 } 
  31.             }); 
  32.             nextImgBtn.setOnClickListener(new View.OnClickListener() { 
  33.   
  34.                 @Override 
  35.                 public void onClick(View v) { 
  36.                     mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1); 
  37.                 } 
  38.             }); 
  39.   
  40.             Calendar c = Calendar.getInstance(); 
  41.   
  42.             CalendarCard[] views = new CalendarCard[3]; 
  43.             for (int i = 0; i < 3; i++) { 
  44.                 views[i] = new CalendarCard(context, new OnCellClickListener() { 
  45.   
  46.                     @Override 
  47.                     public void clickDate(CustomDate date) { 
  48.                         if (listener != null) { 
  49.                             listener.clickDate(date); 
  50.                         } 
  51.                         // window.dismiss(); 
  52.                     } 
  53.   
  54.                     @Override 
  55.                     public void changeDate(CustomDate date) { 
  56.                         slide_time.setText(date.year + "年" + date.month + "月"); 
  57.                     } 
  58.                 }, liang); 
  59.             } 
  60.   
  61.             adapter = new CalendarViewAdapter<calendarcard>(views); 
  62.             setViewPager(); 
  63.   
  64.             // 设置popWindow弹出窗体可点击,这句话必须添加,并且是true 
  65.             instance.setFocusable(true); 
  66.   
  67.             // 实例化一个ColorDrawable颜色为半透明 
  68.             ColorDrawable dw = new ColorDrawable(0xffffffff); 
  69.             instance.setBackgroundDrawable(dw); 
  70.             final OnClickListener onclick = onConfirm; 
  71.             btn_confirm.setOnClickListener(new View.OnClickListener() { 
  72.   
  73.                 @Override 
  74.                 public void onClick(View v) { 
  75.                     if (onclick != null) { 
  76.                         onclick.onClick(v); 
  77.                     } 
  78.                     instance.dismiss(); 
  79.                 } 
  80.             }); 
  81.   
  82.             // 设置popWindow的显示和消失动画 
  83.             instance.setAnimationStyle(R.style.mypopwindow_anim_style); 
  84.             // 在底部显示 
  85.             // View parent = activity.findViewById(R.id.contact_main); 
  86.             // window.showAtLocation(parent, GRAVITY_FOR_POP, X_LOCATION, 
  87.             // Y_LOCATION); 
  88.             final OnDismissListener dListener = onDismiss; 
  89.             // popWindow消失监听方法 
  90.             instance.setOnDismissListener(new OnDismissListener() { 
  91.   
  92.                 @Override 
  93.                 public void onDismiss() { 
  94.                     if (dListener != null) { 
  95.                         dListener.onDismiss(); 
  96.                     } 
  97.                     System.out.println("popWindow消失"); 
  98.                 } 
  99.             }); 
  100.         } 
  101.         return instance; 
  102.     }</calendarcard> 

 

责任编辑:倪明 来源: devstore
相关推荐

2013-06-17 10:31:42

WP7开发日历控件源码下载

2009-08-11 15:46:15

C#日历控件

2015-02-11 17:57:36

iOS源码年日历

2009-08-03 13:43:02

C#日历控件

2009-08-04 14:00:56

ASP.NET弹出式日

2015-05-27 07:44:34

日历控件 jQueryCSS3

2013-06-17 12:28:00

WP7开发Windows Pho控件倾斜特效源

2015-02-11 17:49:35

Android源码自定义控件

2012-06-21 09:28:47

jQuery

2015-01-22 15:59:07

Android源码日期时间控件SelectTime

2014-07-15 09:26:13

swiftiosMPGNotifica

2009-07-31 10:23:09

ASP.NET源码DateTimePic

2009-08-28 15:05:35

C#编写Calenda

2014-07-09 09:13:16

Web效果Web特效

2011-01-21 16:34:15

2012-05-31 14:46:32

jQuery

2013-06-17 13:47:41

WP7开发Windows Pho文本框水印控件

2011-01-21 17:00:49

Thunderbird日历

2021-05-11 08:30:54

前端css技术热点

2017-05-04 18:00:43

iOS日历SKCalendarV
点赞
收藏

51CTO技术栈公众号