自定义日历
2016-06-27 00:00
567 查看
摘要: 一个自定义日历 可左右滑动 可添加点击事件 日期圆点背景
源码地址 https://github.com/Reone/CalendarView
在 http://blog.csdn.net/wwj_748/article/details/42244865 基础上进行修改,感谢
效果图
自定义view
Activity 中引用
activity_main_calendar.xml
本博客原地址:http://my.oschina.net/reone/blog/701483
源码地址 https://github.com/Reone/CalendarView
在 http://blog.csdn.net/wwj_748/article/details/42244865 基础上进行修改,感谢
效果图
自定义view
Activity 中引用
package com.reone.calendarview; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.view.View; import android.view.Window; import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; import com.reone.calendarview.view.CalendarCard; import com.reone.calendarview.view.CalendarPickView; import com.reone.calendarview.view.CustomDate; public class MainCalendarActivity extends Activity implements View.OnClickListener{ private CalendarPickView mCalendarPickView; private Context mContext; private ImageButton preImgBtn, nextImgBtn; private TextView monthText; private ImageButton closeImgBtn; private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main_calendar); mContext =this; mCalendarPickView = (CalendarPickView) findViewById(R.id.calendar_pick_view); mViewPager = mCalendarPickView.getViewPager(); preImgBtn = (ImageButton) this.findViewById(R.id.btnPreMonth); nextImgBtn = (ImageButton) this.findViewById(R.id.btnNextMonth); monthText = (TextView) this.findViewById(R.id.tvCurrentMonth); closeImgBtn = (ImageButton) this.findViewById(R.id.btnClose); preImgBtn.setOnClickListener(this); nextImgBtn.setOnClickListener(this); closeImgBtn.setOnClickListener(this); monthText.setText(mCalendarPickView.getCurrentDate().month+"月"); mCalendarPickView.setOnItemClickListener(new CalendarPickView.OnItemClickListener() { @Override public void onClick(CustomDate date, CalendarCard.State state) { Toast.makeText(mContext,"onClick " + date.toString(), Toast.LENGTH_SHORT).show(); } @Override public void onChangeDate(CustomDate date) { monthText.setText(date.month + "月"); } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnPreMonth: mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1); break; case R.id.btnNextMonth: mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1); break; case R.id.btnClose: finish(); break; default: break; } } }
activity_main_calendar.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#f6f1ea" > <ImageButton android:id="@+id/btnPreMonth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="33dip" android:layout_toLeftOf="@+id/tvCurrentMonth" android:background="@android:drawable/ic_media_previous" /> <ImageButton android:id="@+id/btnNextMonth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="33dip" android:layout_toRightOf="@+id/tvCurrentMonth" android:background="@android:drawable/ic_media_next" /> <TextView android:id="@+id/tvCurrentMonth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_centerVertical="true" android:text="11月" android:textColor="#323232" android:textSize="22sp" /> <ImageButton android:id="@+id/btnClose" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="15dp" android:background="@android:drawable/ic_menu_close_clear_cancel" /> </RelativeLayout> <com.reone.calendarview.view.CalendarPickView android:id="@+id/calendar_pick_view" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> </LinearLayout>
本博客原地址:http://my.oschina.net/reone/blog/701483
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories