Android史上功能最全的日曆控制項

來源:互聯網
上載者:User

標籤:android 最全 日曆 周數 控制項

※效果




※使用方法
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();}});}}}
※Demo下載http://download.csdn.net/detail/u010785585/8016687



Android史上功能最全的日曆控制項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.