android日历控件(一)
自定义日历并且具备设置今天以前的时间不可点选,以前的颜色和当前的颜色不同,以及获取两次点击日期之间间隔的天数所以说细节比较多
个人习惯,先上图
靠,笔记本不知道怎么回事,禁用到触摸板之后 再次唤醒屏幕触摸板又恢复正常了,而且快捷键可能被占用还是怎么着,找不到关闭快捷键的图标,关闭的话 需要重启才行,懒得管了 蛋疼,瘪犊子玩意!
项目中用到日历控件,需求大致是这样:
有两处用到日历控件: 一个是显示每个月份全部的天数,实现滑动跳到下一月份,以前月份的天数不可点选,点击今天及以后的天数的时候刷新页面显示日期,获取两次点击的间隔数以及相关的计算(android这方面用原生的话肯定不行,而且后台和ios商量用ios风格,android仿ios这方面的轮子就更少了,没办法,遇到不会的就查呗,查不到就问呗,问不到的只能"靠"了);
第二个需求是显示每周的天数实现多选,这个很简单。
重点来了:::》》》
所以说要完全自定义日历并且具备设置以前或者以后时间不可点选,以前的颜色和当前的颜色不同,以及获取两次点击日期之间间隔的天数所以说细节比较多,,,
Calendar大家都清楚,获取时间:
不断刷新秒,简单的时钟就出来了,
package com.example.mydemo;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
/**
* 获取时间
*/
private int mHour;
private int mMinute;
private int mYear;
private int mMonth;
private int mDay;
private TextView text;
private int second;
private int ampm;
private Handler mHandler=new Handler(){};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.text);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
init();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mHandler.postDelayed(this, 1000);
init();
text.setText("年:"+mYear+",月:"+mMonth+",日:"+mDay+","+mHour+":"+mMinute+":秒"+second);
}
}, 1000);
}
private void init(){
Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR); //获取当前年份
mMonth = c.get(Calendar.MONTH)+1;//获取当前月份
mDay = c.get(Calendar.DAY_OF_MONTH);//获取当前月份的日期号码
mHour = c.get(Calendar.HOUR_OF_DAY);//获取当前的小时数
mMinute = c.get(Calendar.MINUTE);//获取当前的分钟数
second = c.get(Calendar.SECOND);//获取当前的秒数
ampm = c.get(Calendar.AM_PM); //0-上午;1-下午
//当前年的第几周 这个需求感觉没什么用
int week_of_year = c.get(Calendar.WEEK_OF_YEAR);
//当前月的第几周
int week_of_month = c.get(Calendar.WEEK_OF_MONTH);
//当前年的第几天
int day_of_year = c.get(Calendar.DAY_OF_YEAR);
mHandler.sendEmptyMessage(0);
}
/**
* 点击出现日历弹框
*/
private PickDialog dialog;
private Button button;
private void getData(){
dialog = new PickDialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.show();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button:
getData();
break;
default:
break;
}
}
}
-------------------------------
由此,封装出工具类,这种工具类 轮子比较多,
package com.example.mydemo.util;
import java.io.Serializable;
/**
* 自定义日期类
* @author kcw001
*/
public class CustomDate implements Serializable{
private static final long serialVersionUID = 1L;
public int year;
public int month;
public int day;
public int week;
public CustomDate(int year,int month,int day){
if(month > 12){
month = 1;
year++;
}else if(month <1){
month = 12;
year--;
}
this.year = year;
this.month = month;
this.day = day;
}
public CustomDate(){
this.year = DateUtils.getYear();
this.month = DateUtils.getMonth();
this.day = DateUtils.getCurrentMonthDay();
}
public static CustomDate modifiDayForObject(CustomDate date,int day){
CustomDate modifiDate = new CustomDate(date.year,date.month,day);
return modifiDate;
}
@Override
public String toString() {
return year+"-"+month+"-"+day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getWeek() {
return week;
}
public void setWeek(int week) {
this.week = week;
}
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.annotation.SuppressLint;
public class DateUtils {
public static String[] weekName = { "周日", "周一", "周二", "周三", "周四", "周五","周六" };
public static int getMonthDays(int year, int month) {
if (month > 12) {
month = 1;
year += 1;
} else if (month < 1) {
month = 12;
year -= 1;
}
int[] arr = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int days = 0;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
arr[1] = 29; // 闰年2月29天
}
try {
days = arr[month - 1];
} catch (Exception e) {
e.getStackTrace();
}
return days;
}
public static int getYear() {
return Calendar.getInstance().get(Calendar.YEAR);
}
public static int getMonth() {
return Calendar.getInstance().get(Calendar.MONTH) + 1;
}
public static int getCurrentMonthDay() {
return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
}
public static int getWeekDay() {
return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
}
public static int getHour() {
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
}
public static int getMinute() {
return Calendar.getInstance().get(Calendar.MINUTE);
}
public static CustomDate getNextSunday() {
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, 7 - getWeekDay()+1);
CustomDate date = new CustomDate(c.get(Calendar.YEAR),
c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_MONTH));
return date;
}
public static int[] getWeekSunday(int year, int month, int day, int pervious) {
int[] time = new int[3];
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
c.add(Calendar.DAY_OF_MONTH, pervious);
time[0] = c.get(Calendar.YEAR);
time[1] = c.get(Calendar.MONTH )+1;
time[2] = c.get(Calendar.DAY_OF_MONTH);
return time;
}
public static int getWeekDayFromDate(int year, int month) {
Calendar cal = Calendar.getInstance();
cal.setTime(getDateFromString(year, month));
int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (week_index < 0) {
week_index = 0;
}
return week_index;
}
@SuppressLint("SimpleDateFormat")
public static Date getDateFromString(int year, int month) {
String dateString = year + "-" + (month > 9 ? month : ("0" + month))
+ "-01";
Date date = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
date = sdf.parse(dateString);
} catch (ParseException e) {
System.out.println(e.getMessage());
}
return date;
}
public static boolean isToday(CustomDate date){
return(date.year == DateUtils.getYear() &&
date.month == DateUtils.getMonth()
&& date.day == DateUtils.getCurrentMonthDay());
}
public static boolean isCurrentMonth(CustomDate date){
return(date.year == DateUtils.getYear() &&
date.month == DateUtils.getMonth());
}
/**
* 返回当天日期
* String 格式: "yyyy-MM-dd" "yyyy-MM-dd HH:mm:ss:SS"等
*/
public static String getNowData(Date data,String dateformat) {
// Date data = new Date();
SimpleDateFormat format = new SimpleDateFormat(dateformat);// 可以方便地修改日期格式
String now = format.format(data);
return now;
}
/**
* 传入字符串
* @param point1 起始日期
* @param point2 终止日期
* @return
*/
public static String getDays(String point1, String point2,boolean flag) {
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
long day = 0;
try {
java.util.Date date = myFormatter.parse(point1);
java.util.Date mydate = myFormatter.parse(point2);
day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
if(flag)
day = Math.abs(day);
} catch (Exception e) {
return "";
}
return day + "";
}
public static Calendar getDate(int day,int month,int year) {
Calendar calDate = Calendar.getInstance();
calDate.clear();
calDate.set(Calendar.YEAR, year);
calDate.set(Calendar.MONTH, month);
calDate.set(Calendar.DAY_OF_MONTH, day);
return calDate;
}
/**
* 传入Date对象计算相隔天数
*/
public static int getDays(Calendar fromCalendar,Calendar toCalendar){
return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
}
public Calendar getDate2(Date date,int day,int month,int year) {
Calendar calDate = Calendar.getInstance();
calDate.setTime(date);
calDate.set(Calendar.YEAR, year);
calDate.set(Calendar.MONTH, month);
calDate.set(Calendar.DAY_OF_MONTH, day);
return calDate;
}
}
====================================
DateUtil工具类
package com.example.mydemo.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.annotation.SuppressLint;
import android.provider.ContactsContract.Data;
public class DateUtils {
public static String[] weekName = { "周日", "周一", "周二", "周三", "周四", "周五","周六" };
public static int getMonthDays(int year, int month) {
if (month > 12) {
month = 1;
year += 1;
} else if (month < 1) {
month = 12;
year -= 1;
}
int[] arr = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int days = 0;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
arr[1] = 29; // 闰年2月29天
}
try {
days = arr[month - 1];
} catch (Exception e) {
e.getStackTrace();
}
return days;
}
public static int getYear() {
return Calendar.getInstance().get(Calendar.YEAR);
}
public static int getMonth() {
return Calendar.getInstance().get(Calendar.MONTH) + 1;
}
public static int getCurrentMonthDay() {
return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
}
public static int getWeekDay() {
return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
}
public static int getHour() {
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
}
public static int getMinute() {
return Calendar.getInstance().get(Calendar.MINUTE);
}
public static CustomDate getNextSunday() {
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, 7 - getWeekDay()+1);
CustomDate date = new CustomDate(c.get(Calendar.YEAR),
c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_MONTH));
return date;
}
public static int[] getWeekSunday(int year, int month, int day, int pervious) {
int[] time = new int[3];
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
c.add(Calendar.DAY_OF_MONTH, pervious);
time[0] = c.get(Calendar.YEAR);
time[1] = c.get(Calendar.MONTH )+1;
time[2] = c.get(Calendar.DAY_OF_MONTH);
return time;
}
public static int getWeekDayFromDate(int year, int month) {
Calendar cal = Calendar.getInstance();
cal.setTime(getDateFromString(year, month));
int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (week_index < 0) {
week_index = 0;
}
return week_index;
}
@SuppressLint("SimpleDateFormat")
public static Date getDateFromString(int year, int month) {
String dateString = year + "-" + (month > 9 ? month : ("0" + month))
+ "-01";
Date date = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
date = sdf.parse(dateString);
} catch (ParseException e) {
System.out.println(e.getMessage());
}
return date;
}
public static boolean isToday(CustomDate date){
return(date.year == DateUtils.getYear() &&
date.month == DateUtils.getMonth()
&& date.day == DateUtils.getCurrentMonthDay());
}
public static boolean isCurrentMonth(CustomDate date){
return(date.year == DateUtils.getYear() &&
date.month == DateUtils.getMonth());
}
/**
* 返回当天日期
* String 格式: "yyyy-MM-dd" "yyyy-MM-dd HH:mm:ss:SS"等
*/
public static String getNowData(Date data,String dateformat) {
// Date data = new Date();
SimpleDateFormat format = new SimpleDateFormat(dateformat);// 可以方便地修改日期格式
String now = format.format(data);
return now;
}
/**
* 传入字符串
* @param point1 起始日期
* @param point2 终止日期
* @return
*/
public static String getDays(String point1, String point2,boolean flag) {
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
long day = 0;
try {
java.util.Date date = myFormatter.parse(point1);
java.util.Date mydate = myFormatter.parse(point2);
day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
if(flag)
day = Math.abs(day);
} catch (Exception e) {
return "";
}
return day + "";
}
public static Calendar getDate(int day,int month,int year) {
Calendar calDate = Calendar.getInstance();
calDate.clear();
calDate.set(Calendar.YEAR, year);
calDate.set(Calendar.MONTH, month);
calDate.set(Calendar.DAY_OF_MONTH, day);
return calDate;
}
/**
* 传入Date对象计算相隔天数
*/
public static int getDays(Calendar fromCalendar,Calendar toCalendar){
return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
}
public Calendar getDate2(Date date,int day,int month,int year) {
Calendar calDate = Calendar.getInstance();
calDate.setTime(date);
calDate.set(Calendar.YEAR, year);
calDate.set(Calendar.MONTH, month);
calDate.set(Calendar.DAY_OF_MONTH, day);
return calDate;
}
}
=========================
package com.example.mydemo;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import com.example.mydemo.util.CustomDate;
import com.example.mydemo.util.DateUtils;
public class CalendarView extends View{
private static final String TAG = "CalendarView";
/**
* 两种模式 (月份和星期)
*/
public static final int MONTH_STYLE = 0;
public static final int WEEK_STYLE = 1;
private static final int TOTAL_COL = 7;
private static final int TOTAL_ROW = 6;
private Paint mCirclePaint;
private Paint mTextPaint;
private int mViewWidth;
private int mViewHight;
private int mCellSpace;
private Row rows[] = new Row[TOTAL_ROW];
private static CustomDate mShowDate;//自定义的日期 包括year month day
public static int style = MONTH_STYLE;
private static final int WEEK = 7;
private CallBack mCallBack;//回调
private int touchSlop;
private boolean callBackCellSpace;
public interface CallBack {
void clickDate(CustomDate date);//回调点击的日期
void onMesureCellHeight(int cellSpace);//回调cell的高度确定slidingDrawer高度
void changeDate(CustomDate date);//回调滑动viewPager改变的日期
void onClickOnDate();//设置日期点击item事件
}
public CalendarView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
public CalendarView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CalendarView(Context context) {
super(context);
init(context);
}
public CalendarView(Context context, int style, CallBack mCallBack) {
super(context);
CalendarView.style = style;
this.mCallBack = mCallBack;
init(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (int i = 0; i < TOTAL_ROW; i++) {
if (rows[i] != null)
rows[i].drawCells(canvas);
}
}
private void init(Context context) {
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint.setStyle(Paint.Style.FILL);
mCirclePaint.setColor(Color.parseColor("#F24949"));
touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
initDate();
}
private void initDate() {
if (style == MONTH_STYLE) {
mShowDate = new CustomDate();
} else if(style == WEEK_STYLE ) {
mShowDate = DateUtils.getNextSunday();
}
fillDate();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mViewWidth = w;
mViewHight = h;
mCellSpace = Math.min(mViewHight / TOTAL_ROW, mViewWidth / TOTAL_COL);
if (!callBackCellSpace) {
mCallBack.onMesureCellHeight(mCellSpace);
callBackCellSpace = true;
}
mTextPaint.setTextSize(mCellSpace / 3);
}
private Cell mClickCell;
private float mDownX;
private float mDownY;
/*
*
* 触摸事件为了确定点击的位置日期
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mDownX = event.getX();
mDownY = event.getY();
break;
case MotionEvent.ACTION_UP:
float disX = event.getX() - mDownX;
float disY = event.getY() - mDownY;
if (Math.abs(disX) < touchSlop && Math.abs(disY) < touchSlop) {
int col = (int) (mDownX / mCellSpace);
int row = (int) (mDownY / mCellSpace);
//执行点击事件
mCallBack.onClickOnDate();
measureClickCell(col, row);
}
break;
}
return true;
}
private void measureClickCell(int col, int row) {
if (col >= TOTAL_COL || row >= TOTAL_ROW)
return;
if (mClickCell != null) {
rows[mClickCell.j].cells[mClickCell.i] = mClickCell;
}
if (rows[row] != null) {
mClickCell = new Cell(rows[row].cells[col].date,
rows[row].cells[col].state, rows[row].cells[col].i,
rows[row].cells[col].j);
rows[row].cells[col].state = State.CLICK_DAY;
CustomDate date = rows[row].cells[col].date;
date.week = col;
mCallBack.clickDate(date);
invalidate();
}
}
// 组
class Row {
public int j;
Row(int j) {
this.j = j;
}
public Cell[] cells = new Cell[TOTAL_COL];
public void drawCells(Canvas canvas) {
for (int i = 0; i < cells.length; i++) {
if (cells[i] != null)
cells[i].drawSelf(canvas);
}
}
}
// 单元格
class Cell {
public CustomDate date;
public State state;
public int i;
public int j;
public Cell(CustomDate date, State state, int i, int j) {
super();
this.date = date;
this.state = state;
this.i = i;
this.j = j;
}
// 绘制一个单元格 如果颜色需要自定义可以修改
public void drawSelf(Canvas canvas) {
switch (state) {
case CURRENT_MONTH_DAY:
mTextPaint.setColor(Color.parseColor("#80000000"));//偏红
break;
case NEXT_MONTH_DAY:
case PAST_MONTH_DAY:
mTextPaint.setColor(Color.parseColor("#40000000"));//暗色
break;
case TODAY:
mTextPaint.setColor(Color.parseColor("#F24949"));//红色
break;
case BEFORE_DAY:
mTextPaint.setColor(Color.parseColor("#F24949"));//红色
break;
case CLICK_DAY:
mTextPaint.setColor(Color.parseColor("#fffffe"));//白色
canvas.drawCircle((float) (mCellSpace * (i + 0.5)),
(float) ((j + 0.5) * mCellSpace), mCellSpace / 2,
mCirclePaint);
break;
}
// 绘制文字
String content = date.day+"";
canvas.drawText(content,
(float) ((i+0.5) * mCellSpace - mTextPaint.measureText(content)/2),
(float) ((j + 0.7) * mCellSpace - mTextPaint.measureText(
content, 0, 1) / 2), mTextPaint);
}
}
/**
*
* @author huang
* cell的state
*当前月日期,过去的月的日期,下个月的日期,今天,点击的日期
*
*/
enum State {
CURRENT_MONTH_DAY, PAST_MONTH_DAY, NEXT_MONTH_DAY, TODAY, CLICK_DAY,BEFORE_DAY;
}
/**
* 填充日期的数据
*/
private void fillDate() {
if (style == MONTH_STYLE) {
fillMonthDate();
} else if(style == WEEK_STYLE) {
fillWeekDate();
}
mCallBack.changeDate(mShowDate);
}
/**
* 填充星期模式下的数据 默认通过当前日期得到所在星期天的日期,然后依次填充日期
*/
private void fillWeekDate() {
int lastMonthDays = DateUtils.getMonthDays(mShowDate.year, mShowDate.month-1);
rows[0] = new Row(0);
int day = mShowDate.day;
for (int i = TOTAL_COL -1; i >= 0 ; i--) {
day -= 1;
if (day < 1) {
day = lastMonthDays;
}
CustomDate date = CustomDate.modifiDayForObject(mShowDate, day);
if (DateUtils.isToday(date)) {
mClickCell = new Cell(date, State.TODAY, i, 0);
date.week = i;
mCallBack.clickDate(date);
rows[0].cells[i] = new Cell(date, State.CLICK_DAY, i, 0);
continue;
}
rows[0].cells[i] = new Cell(date, State.CURRENT_MONTH_DAY,i, 0);
}
}
/**
* 填充月份模式下数据 通过getWeekDayFromDate得到一个月第一天是星期几就可以算出所有的日期的位置 然后依次填充
* 重构一下
*/
private void fillMonthDate() {
int monthDay = DateUtils.getCurrentMonthDay();
int lastMonthDays = DateUtils.getMonthDays(mShowDate.year, mShowDate.month - 1);
int currentMonthDays = DateUtils.getMonthDays(mShowDate.year, mShowDate.month);
int firstDayWeek = DateUtils.getWeekDayFromDate(mShowDate.year, mShowDate.month);
boolean isCurrentMonth = false;
if (DateUtils.isCurrentMonth(mShowDate)) {
isCurrentMonth = true;
}
int day = 0;
for (int j = 0; j < TOTAL_ROW; j++) {
rows[j] = new Row(j);
for (int i = 0; i < TOTAL_COL; i++) {
int postion = i + j * TOTAL_COL;
if (postion >= firstDayWeek
&& postion < firstDayWeek + currentMonthDays) {
day++;// 这个月的
if (isCurrentMonth && day == monthDay) {//今天
CustomDate date = CustomDate.modifiDayForObject(mShowDate, day);
mClickCell = new Cell(date,State.TODAY, i,j);
date.week = i;
mCallBack.clickDate(date);
rows[j].cells[i] = new Cell(date,State.CLICK_DAY, i,j);
continue;
}if (isCurrentMonth && day < monthDay) { // 如果比这个月的今天要XIAO,表示还没到
rows[j].cells[i] = new Cell(
CustomDate.modifiDayForObject(mShowDate, day),
State.BEFORE_DAY, i, j);
continue;
}
rows[j].cells[i] = new Cell(CustomDate.modifiDayForObject(mShowDate, day),
State.CURRENT_MONTH_DAY, i, j);
} else if (postion < firstDayWeek) {
rows[j].cells[i] = new Cell(new CustomDate(mShowDate.year, mShowDate.month-1, lastMonthDays - (firstDayWeek- postion - 1)), State.PAST_MONTH_DAY, i, j);
} else if (postion >= firstDayWeek + currentMonthDays) {
rows[j].cells[i] = new Cell((new CustomDate(mShowDate.year, mShowDate.month+1, postion - firstDayWeek - currentMonthDays + 1)), State.NEXT_MONTH_DAY, i, j);
}
}
}
}
public void update() {
fillDate();
invalidate();
}
public void backToday(){
initDate();
invalidate();
}
//切换style
public void switchStyle(int style) {
CalendarView.style = style;
if (style == MONTH_STYLE) {
update();
} else if (style == WEEK_STYLE) {
int firstDayWeek = DateUtils.getWeekDayFromDate(mShowDate.year,
mShowDate.month);
int day = 1 + WEEK - firstDayWeek;
mShowDate.day = day;
update();
}
}
//向右滑动
public void rightSilde() {
if (style == MONTH_STYLE) {
if (mShowDate.month == 12) {
mShowDate.month = 1;
mShowDate.year += 1;
} else {
mShowDate.month += 1;
}
} else if (style == WEEK_STYLE) {
int currentMonthDays = DateUtils.getMonthDays(mShowDate.year, mShowDate.month);
if (mShowDate.day + WEEK > currentMonthDays) {
if (mShowDate.month == 12) {
mShowDate.month = 1;
mShowDate.year += 1;
} else {
mShowDate.month += 1;
}
mShowDate.day = WEEK - currentMonthDays + mShowDate.day;
}else{
mShowDate.day += WEEK;
}
}
update();
}
//向左滑动
public void leftSilde() {
if (style == MONTH_STYLE) {
if (mShowDate.month == 1) {
mShowDate.month = 12;
mShowDate.year -= 1;
} else {
mShowDate.month -= 1;
}
} else if (style == WEEK_STYLE) {
int lastMonthDays = DateUtils.getMonthDays(mShowDate.year, mShowDate.month);
if (mShowDate.day - WEEK < 1) {
if (mShowDate.month == 1) {
mShowDate.month = 12;
mShowDate.year -= 1;
} else {
mShowDate.month -= 1;
}
mShowDate.day = lastMonthDays - WEEK + mShowDate.day;
}else{
mShowDate.day -= WEEK;
}
Log.i(TAG, "leftSilde"+mShowDate.toString());
}
update();
}
}
====================================
package com.example.mydemo;
import android.content.Context;
import com.example.mydemo.CalendarView.CallBack;
/**
* calendview辅助类 在这里 完成回调今天等功能
* @author kcw001
*
*/
public class CalendarViewBuilder {
private CalendarView[] calendarViews;
/**
* create 多个calendarviews
* @param context
* @param count
* @param style
* @param callBack
* @return
*/
public CalendarView[] createMassCalendarViews(Context context,int count,int style,CallBack callBack){
calendarViews = new CalendarView[count];
for(int i = 0; i < count;i++){
calendarViews[i] = new CalendarView(context, style,callBack);
}
return calendarViews;
}
public CalendarView[] createMassCalendarViews(Context context,int count,CallBack callBack){
return createMassCalendarViews(context, count, CalendarView.MONTH_STYLE,callBack);
}
/**
* 切换CandlendarView的样式
* @param style
*/
public void swtichCalendarViewsStyle(int style){
if(calendarViews != null)
for(int i = 0 ;i < calendarViews.length;i++){
calendarViews[i].switchStyle(style);
}
}
/**
* CandlendarView回到当前日期
*/
public void backTodayCalendarViews(){
if(calendarViews != null)
for(int i = 0 ;i < calendarViews.length;i++){
calendarViews[i].backToday();
}
}
}
======================================
package com.example.mydemo;
import android.support.v4.view.ViewPager.OnPageChangeListener;
public class CalendarViewPagerLisenter implements OnPageChangeListener{
private SildeDirection mDirection = SildeDirection.NO_SILDE;
int mCurrIndex = 498;
private CalendarView[] mShowViews;
public CalendarViewPagerLisenter(CustomViewPagerAdapter<CalendarView> viewAdapter) {
super();
this.mShowViews = viewAdapter.getAllItems();
}
@Override
public void onPageSelected(int arg0) {
measureDirection(arg0);
updateCalendarView(arg0);
}
private void updateCalendarView(int arg0) {
if(mDirection == SildeDirection.RIGHT){
mShowViews[arg0 % mShowViews.length].rightSilde();
}else if(mDirection == SildeDirection.LEFT){
mShowViews[arg0 % mShowViews.length].leftSilde();
}
mDirection = SildeDirection.NO_SILDE;
}
/**
* 判断滑动方向
* @param arg0
*/
private void measureDirection(int arg0) {
if (arg0 > mCurrIndex) {
mDirection = SildeDirection.RIGHT;
} else if (arg0 < mCurrIndex) {
mDirection = SildeDirection.LEFT;
}
mCurrIndex = arg0;
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
//反射
enum SildeDirection {
RIGHT, LEFT, NO_SILDE;
}
}
----------------------------------------------------------------------------------
package com.example.mydemo;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
/**
* 自定义布局 绘制文字和园
* @author kcw001
*/
public class CircleTextView extends View {
private String mText = "订";
private OnClickListener onClickListener;
private Paint mCirclePaint;
private Paint mTextPaint;
private int mViewWidth;
private int mViewHight;
public CircleTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
init();
}
public CircleTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
init();
}
public CircleTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
TypedArray t = context.obtainStyledAttributes(attrs,
R.styleable.CircleTextView);
mText = t.getString(R.styleable.CircleTextView_text);
t.recycle();
init();
}
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}
public void setmText(String mText) {
this.mText = mText;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(mViewWidth / 2, mViewWidth / 2, mViewWidth / 2,
mCirclePaint);
canvas.drawText(mText,
(mViewWidth - mTextPaint.measureText(mText)) / 2,
(mViewHight + mTextPaint.measureText(mText) / 2) / 2,
mTextPaint);
}
public void init() {
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
initPaint(false);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mViewWidth = w;
mViewHight = h;
mTextPaint.setTextSize(mViewWidth / 3);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initPaint(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (onClickListener != null)
onClickListener.onClick(this);
initPaint(false);
break;
}
invalidate();
return true;
}
private void initPaint(boolean isPress) {
if (!isPress) {
mCirclePaint.setStyle(Paint.Style.STROKE);
mCirclePaint.setColor(Color.parseColor("#40000000"));
mTextPaint.setColor(Color.parseColor("#80000000"));
} else {
mCirclePaint.setStyle(Paint.Style.FILL);
mCirclePaint.setColor(Color.parseColor("#F24949"));
mTextPaint.setColor(Color.parseColor("#fffffe"));
}
}
}
============================================
package com.example.mydemo;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
/**
* 日历适配器
* @author kcw001
*
*/
public class CustomViewPagerAdapter<V extends View> extends PagerAdapter {
private V[] views;
public CustomViewPagerAdapter(V[] views) {
super();
this.views = views;
}
@Override
public void finishUpdate(View arg0) {
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public Object instantiateItem(View arg0, int arg1) {
if (((ViewPager) arg0).getChildCount() == views.length) {
((ViewPager) arg0).removeView(views[arg1 % views.length]);
}
((ViewPager) arg0).addView(views[arg1 % views.length], 0);
return views[arg1 % views.length];
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == (arg1);
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
// TODO Auto-generated method stub
}
@Override
public void startUpdate(View arg0) {
}
public V[] getAllItems() {
return views;
}
}
=========================
package com.example.mydemo;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.SlidingDrawer.OnDrawerScrollListener;
import android.widget.TextView;
import com.example.mydemo.CalendarView.CallBack;
import com.example.mydemo.util.CustomDate;
import com.example.mydemo.util.DateUtils;
public class PickDialog extends Dialog implements OnClickListener,CallBack{
private Context context;
private PickDialogListener pickDialogListener;
private LinearLayout dialog_data;
private CalendarViewBuilder builder = new CalendarViewBuilder();//创建view的辅助类
private TextView monthCalendarView;
private TextView weekCalendarView;
private CircleTextView mSubscibeCircleView;
private CircleTextView mNowCircleView;
private CircleTextView mAddCircleView;
private LinearLayout layout;
//年月周
private TextView showYearView;
private TextView showMonthView;
private TextView showWeekView;
private ViewPager viewPager;
private CalendarView[] views;
private LayoutInflater inflater;
private View mContentPager;
private SlidingDrawer mSlidingDrawer;
private CustomDate mClickDate;
public PickDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.context=context;
}
public PickDialog(Context context, int theme, PickDialogListener pickDialogListener) {
super(context);
// TODO Auto-generated constructor stub
this.context=context;
this.pickDialogListener=pickDialogListener;
}
//如何调用接口里面的
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
inflater = LayoutInflater.from(context);
layout = (LinearLayout) inflater.inflate(
R.layout.dialog_data, null);
this.setCanceledOnTouchOutside(true);
this.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
dismiss();
}
});
init();
this.setContentView(layout);
}
private void init(){
viewPager = (ViewPager) layout.findViewById(R.id.viewpager);
showMonthView = (TextView)layout.findViewById(R.id.show_month_view);
showYearView = (TextView)layout.findViewById(R.id.show_year_view);
showWeekView = (TextView)layout.findViewById(R.id.show_week_view);
views = builder.createMassCalendarViews(getContext(), 5, this);
monthCalendarView = (TextView) layout.findViewById(R.id.month_calendar_button);
weekCalendarView = (TextView) layout.findViewById(R.id.week_calendar_button);
mContentPager = layout.findViewById(R.id.contentPager);
mSlidingDrawer = (SlidingDrawer)layout.findViewById(R.id.sildingDrawer);
mSubscibeCircleView = (CircleTextView)layout.findViewById(R.id.subscibe_circle_view);
mNowCircleView = (CircleTextView)layout.findViewById(R.id.now_circle_view);//点击今天回到今天
mAddCircleView = (CircleTextView)layout.findViewById(R.id.add_circle_view);
monthCalendarView.setOnClickListener(this);
weekCalendarView.setOnClickListener(this);
mSubscibeCircleView.setOnClickListener(this);
mNowCircleView.setOnClickListener(this);
mAddCircleView.setOnClickListener(this);
setViewPager();
setOnDrawListener();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.month_calendar_button://月份
swtichBackgroundForButton(true);
builder.swtichCalendarViewsStyle(CalendarView.MONTH_STYLE);
mSlidingDrawer.close();
break;
case R.id.week_calendar_button://周
swtichBackgroundForButton(false);
mSlidingDrawer.open();
break;
case R.id.now_circle_view://点击今天会到今天
builder.backTodayCalendarViews();
break;
case R.id.add_circle_view://加号 点击进入编辑
break;
case R.id.subscibe_circle_view:
dismiss();
}
}
private void swtichBackgroundForButton(boolean isMonth){
if(isMonth){
monthCalendarView.setBackgroundResource(R.drawable.press_left_text_bg);
weekCalendarView.setBackgroundColor(Color.TRANSPARENT);
}else{
weekCalendarView.setBackgroundResource(R.drawable.press_right_text_bg);
monthCalendarView.setBackgroundColor(Color.TRANSPARENT);
}
}
private void setViewPager() {
CustomViewPagerAdapter<CalendarView> viewPagerAdapter = new CustomViewPagerAdapter<CalendarView>(views);
viewPager.setAdapter(viewPagerAdapter);
viewPager.setCurrentItem(498);
viewPager.setOnPageChangeListener(new CalendarViewPagerLisenter(viewPagerAdapter));
}
@SuppressWarnings("deprecation")
private void setOnDrawListener() {
mSlidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
builder.swtichCalendarViewsStyle(CalendarView.WEEK_STYLE);
}
});
mSlidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
@Override
public void onScrollStarted() {
builder.swtichCalendarViewsStyle(CalendarView.MONTH_STYLE);
}
@Override
public void onScrollEnded() {
}
});
}
//------------------------------------------------callback
@Override
public void clickDate(CustomDate date) {
// TODO Auto-generated method stub
mClickDate = date;
}
@Override
public void onMesureCellHeight(int cellSpace) {
// TODO Auto-generated method stub
mSlidingDrawer.getLayoutParams().height = mContentPager.getHeight() - cellSpace;
}
@Override
public void changeDate(CustomDate date) {
// TODO Auto-generated method stub
setShowDateViewText(date.year,date.month);
}
private void setShowDateViewText(int year, int month) {
// TODO Auto-generated method stub
showYearView.setText(year+"");
showMonthView.setText(month+"月");
showWeekView.setText(DateUtils.weekName[DateUtils.getWeekDay()-1]);
}
@Override
public void onDetachedFromWindow() {
// TODO Auto-generated method stub
super.onDetachedFromWindow();
}
/**
* 获取到日历天数 点击功能的实现
*/
boolean flag=true;
@Override
public void onClickOnDate() {
int day = mClickDate.getDay();
int month = mClickDate.getMonth();
int year = mClickDate.getYear();
//获取当前日期
//Date data=new Date();
//String nowData = DateUtils.getNowData(data,"yyyy-MM-dd");
//获取点击日期
/* Calendar date2 = DateUtils.getDate(day, month, year);
Date time = date2.getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String nowData = DateUtils.getNowData(time, "yyyy-MM-dd");
Toast.makeText(getContext(), nowData, 0).show();*/
//计算相邻天数相差
/*String days = DateUtils.getDays("2016-1-12", "2016-1-18");
Toast.makeText(context, days, 0).show();*/
/**
* 设置以前的时间不可点选
*/
/*String days = DateUtils.getDays("2016-1-12", "2016-1-18",false);
int num = Integer.parseInt(days);
if(num<0)
Toast.makeText(context, "不可点击", 0).show();
else
Toast.makeText(context, days, 0).show();*/
}
}
====================================
package com.example.mydemo;
public interface PickDialogListener {
public void onLeftBtnClick();
public void onRightBtnClick();
public void onListItemClick(int position, String string);
public void onListItemLongClick(int position, String string);
public void onCancel();
}
==========================================
主页的布局文件
<RelativeLayout 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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="点我"
/>
</RelativeLayout>
==================
dialog页的布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:demo="http://schemas.android.com/apk/res/com.example.mydemo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="@drawable/action_bar_bg"
android:orientation="horizontal" >
<TextView
android:id="@+id/show_month_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="15dip"
android:layout_marginRight="10dip"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="11月"
android:textColor="#fffffe"
android:textSize="24sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/show_month_view"
android:orientation="vertical" >
<TextView
android:id="@+id/show_week_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="bottom|left"
android:paddingBottom="1dip"
android:text="周六"
android:textColor="#80ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/show_year_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="top|left"
android:paddingTop="1dip"
android:text="2015"
android:textColor="#80ffffff"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="80dip"
android:layout_height="25dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/select_view_bg"
android:layout_marginRight="20dip"
android:orientation="horizontal"
>
<TextView
android:id="@+id/month_calendar_button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="月"
android:gravity="center"
android:textColor="#ffffff"
android:clickable="@drawable/press_left_text_bg"
/>
<View
android:layout_width="1px"
android:layout_height="fill_parent"
android:background="#80ffffff"
android:textColor="#ffffff"
/>
<TextView
android:id="@+id/week_calendar_button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="周"
android:gravity="center"
android:textColor="#ffffff"
android:clickable="@drawable/press_right_text_bg"
/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:background="#fffffe"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_alignParentTop="true"
android:background="#20000000" >
</View>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="20dip"
android:layout_marginBottom="2dip"
android:layout_marginTop="2dip" >
<TableRow>
<TextView
style="@style/dateStyle"
android:text="日"
android:textColor="@color/date_1" />
<TextView
style="@style/dateStyle"
android:text="一"
android:textColor="@color/date_2" />
<TextView
style="@style/dateStyle"
android:text="二"
android:textColor="@color/date_2" />
<TextView
style="@style/dateStyle"
android:text="三"
android:textColor="@color/date_2" />
<TextView
style="@style/dateStyle"
android:text="四"
android:textColor="@color/date_2" />
<TextView
style="@style/dateStyle"
android:text="五"
android:textColor="@color/date_2" />
<TextView
style="@style/dateStyle"
android:text="六"
android:textColor="@color/date_1" />
</TableRow>
</TableLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_alignParentTop="true"
android:background="#20000000" >
</View>
</LinearLayout>
<RelativeLayout
android:id="@+id/contentPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#fffffe"
>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_gravity="center"
android:paddingLeft="15dip"
android:paddingRight="10dip"
android:background="#F7F7F7" >
</android.support.v4.view.ViewPager>
<SlidingDrawer
android:id="@+id/sildingDrawer"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:orientation="vertical"
android:layout_alignBottom="@+id/viewpager"
android:handle="@+id/handlerText"
android:content="@+id/contentText"
>
<LinearLayout
android:id="@+id/handlerText"
android:layout_height="wrap_content"
android:minHeight="100dip"
android:background="#fffffe"
android:layout_width="fill_parent"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#30000000" >
</View>
<TextView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:paddingLeft="5dip"
android:text="一座城池2012"
android:textSize="16sp"
android:textColor="#90000000"
android:gravity="center_vertical"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#20000000" >
</View>
</LinearLayout>
<View
android:id="@+id/contentText"
android:background="#fffffe"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</View>
</SlidingDrawer>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="60dip"
android:background="@drawable/bottom_bar_bg" >
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_alignParentTop="true"
android:background="#20000000" >
</View>
<com.example.mydemo.CircleTextView
android:id="@+id/now_circle_view"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerInParent="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
demo:text="今" />
<com.example.mydemo.CircleTextView
android:id="@+id/subscibe_circle_view"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerInParent="true"
android:layout_toLeftOf="@id/now_circle_view"
demo:text="帅" />
<com.example.mydemo.CircleTextView
android:id="@+id/add_circle_view"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerInParent="true"
android:layout_toRightOf="@id/now_circle_view"
demo:text="+" />
</RelativeLayout>
</LinearLayout>
========================================
action_bar_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#F24949"/>
<corners android:topLeftRadius="5dip" android:topRightRadius="5dip" android:bottomLeftRadius="0dip" android:bottomRightRadius="0dip"></corners>
</shape>
===================================================================
bottom_bar_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#F7F7F7"/>
<corners android:topLeftRadius="0dip" android:topRightRadius="0dip" android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip"></corners>
</shape>
==================================
press_left_text_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:topLeftRadius="14dip" android:bottomLeftRadius="14dip"></corners>
<solid android:color="#40ffffff"></solid>
</shape>
==================================
press_right_text_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:topRightRadius="14dip" android:bottomRightRadius="14dip"></corners>
<solid android:color="#40ffffff"></solid>
</shape>
===================================
select_view_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@android:color/transparent"></solid>
<corners android:radius="25dip"></corners>
<stroke android:width="1px" android:color="#80ffffff"></stroke>
</shape>
============================================
value 目录下
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CircleTextView">
<attr name="text" format="string"></attr>
</declare-styleable>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 日历颜色 -->
<color name="date_1">#F24949</color>
<color name="date_2">#40000000</color>
</resources>
styles.xml中添加:
<!-- 文字设置 -->
<style name="dateStyle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:textSize">12sp</item>
</style>
ok,就是这么多了,还有几个细节没处理,明天整理好后
继续
完整demo下载:
http://download.csdn.net/detail/onebelowzero2012/9352913
另附:欢迎加入群一块学习交流,谢谢大家!Android&Go,Let's go! 521039620
有几个地方,后面会更新修改,