Android又一个超漂亮的日历控件

转载 2015年07月09日 11:00:21

2014-07-24      0 个评论    来源:u010785585的专栏  

※效果

\

※使用方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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 + "月");
                }
            });
             
            //上月监听按钮
            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();
                        }
                    });
        }
    }
 
}
</string></string>

※Demo下载

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

android 好看的自定义日历

根据网上查找的资料,可在项目中直接使用的自定义日历控件,综合选择了如下好看的日历: 接下来我们看下代码是如何实现? 首先看布局文件是...

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

效果  实现的效果如下  附上源码地址:http://download.csdn.net/detail/daijin888888/9020535  (...
  • Baby_T
  • Baby_T
  • 2016年10月13日 09:37
  • 651

Android又一个超漂亮的日历控件

※效果 ※使用方法 package com.fancyy.calendarweight; import java.util.ArrayList; import java.util.List; ...

Android中Calendar类的用法总结

Calendar是Android开发中需要获取时间时必不可少的一个工具类,通过这个类可以获得的时间信息还是很丰富的,下面做一个总结,以后使用的时候就不用总是去翻书或者查资料了。...

230_制作简单日历

我们来制作一个简单的日历 其实日历就是一个表格,然后我们把数字填上去 关键就是星期和日期要准确对应 首先是布局 布局我们就最简单的上面是星期日到星期六 日,一,二,三...

日历控件CalendarView

API 11中新加了CalendarView控件,即日历控件。但是如果需要在3.0以下系统中支持,就需要自定义了。 https://github.com/square/android...

超漂亮的JS日历控件

  • 2010年06月22日 11:33
  • 29KB
  • 下载

android 一个很漂亮的控件ObservableScrollView(含片段代码和源码)

转自:http://www.eoeandroid.com/thread-577241-1-1.html 最近看到最美等应用里面有一个特效,自己上网查了下,写了个demo如...

非常漂亮的JS日历控件

  • 2011年05月19日 23:51
  • 95KB
  • 下载

漂亮的日历控件

  • 2012年03月09日 15:21
  • 39KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Android又一个超漂亮的日历控件
举报原因:
原因补充:

(最多只允许输入30个字)