当前位置:   article > 正文

Android日历控件_android 日历控件

android 日历控件

使用Activity 制作一个日历控件

1、日历View

  1. import java.util.Calendar;
  2. import java.util.Date;
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.graphics.Color;
  6. import android.graphics.Paint;
  7. import android.graphics.Path;
  8. import android.graphics.Typeface;
  9. import android.util.AttributeSet;
  10. import android.util.Log;
  11. import android.view.MotionEvent;
  12. import android.view.View;
  13. public class CalendarView extends View implements View.OnTouchListener {
  14. private final static String TAG = "anCalendar";
  15. private Date selectedStartDate;
  16. private Date selectedEndDate;
  17. private Date curDate; // 当前日历显示的月
  18. private Date today; // 今天的日期文字显示红色
  19. private Date downDate; // 手指按下状态时临时日期
  20. private Date showFirstDate, showLastDate; // 日历显示的第一个日期和最后一个日期
  21. private int downIndex; // 按下的格子索引
  22. private Calendar calendar;
  23. private Surface surface;
  24. private int[] date = new int[42]; // 日历显示数字
  25. private int curStartIndex, curEndIndex; // 当前显示的日历起始的索引
  26. // private boolean completed = false; // 为false表示只选择了开始日期,true表示结束日期也选择了
  27. // 给控件设置监听事件
  28. private OnItemClickListener onItemClickListener;
  29. public CalendarView(Context context) {
  30. super(context);
  31. init();
  32. }
  33. public CalendarView(Context context, AttributeSet attrs) {
  34. super(context, attrs);
  35. init();
  36. }
  37. private void init() {
  38. curDate = selectedStartDate = selectedEndDate = today = new Date();
  39. calendar = Calendar.getInstance();
  40. calendar.setTime(curDate);
  41. surface = new Surface();
  42. surface.density = getResources().getDisplayMetrics().density;
  43. setBackgroundColor(surface.bgColor);
  44. setOnTouchListener(this);
  45. }
  46. @Override
  47. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  48. surface.width = getResources().getDisplayMetrics().widthPixels * 4 / 5;
  49. surface.height = (int) (getResources().getDisplayMetrics().heightPixels * 2 / 5);
  50. // if (View.MeasureSpec.getMode(widthMeasureSpec) ==
  51. // View.MeasureSpec.EXACTLY) {
  52. // surface.width = View.MeasureSpec.getSize(widthMeasureSpec);
  53. // }
  54. // if (View.MeasureSpec.getMode(heightMeasureSpec) ==
  55. // View.MeasureSpec.EXACTLY) {
  56. // surface.height = View.MeasureSpec.getSize(heightMeasureSpec);
  57. // }
  58. widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(surface.width, View.MeasureSpec.EXACTLY);
  59. heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(surface.height, View.MeasureSpec.EXACTLY);
  60. setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
  61. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  62. }
  63. @Override
  64. protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  65. Log.d(TAG, "[onLayout] changed:" + (changed ? "new size" : "not change") + " left:" + left + " top:" + top + " right:" + right + " bottom:" + bottom);
  66. if (changed) {
  67. surface.init();
  68. }
  69. super.onLayout(changed, left, top, right, bottom);
  70. }
  71. @Override
  72. protected void onDraw(Canvas canvas) {
  73. Log.d(TAG, "onDraw");
  74. // 画框
  75. canvas.drawPath(surface.boxPath, surface.borderPaint);
  76. // 年月
  77. // String monthText = getYearAndmonth();
  78. // float textWidth = surface.monthPaint.measureText(monthText);
  79. // canvas.drawText(monthText, (surface.width - textWidth) / 2f,
  80. // surface.monthHeight * 3 / 4f, surface.monthPaint);
  81. // 上一月/下一月
  82. // canvas.drawPath(surface.preMonthBtnPath,
  83. // surface.monthChangeBtnPaint);
  84. // canvas.drawPath(surface.nextMonthBtnPath,
  85. // surface.monthChangeBtnPaint);
  86. // 星期
  87. float weekTextY = surface.monthHeight + surface.weekHeight * 3 / 4f;
  88. // 星期背景
  89. // surface.cellBgPaint.setColor(surface.textColor);
  90. // canvas.drawRect(surface.weekHeight, surface.width,
  91. // surface.weekHeight, surface.width, surface.cellBgPaint);
  92. for (int i = 0; i < surface.weekText.length; i++) {
  93. float weekTextX = i * surface.cellWidth + (surface.cellWidth - surface.weekPaint.measureText(surface.weekText[i])) / 2f;
  94. canvas.drawText(surface.weekText[i], weekTextX, weekTextY, surface.weekPaint);
  95. }
  96. // 计算日期
  97. calculateDate();
  98. // 按下状态,选择状态背景色
  99. drawDownOrSelectedBg(canvas);
  100. // write date number
  101. // today index
  102. int todayIndex = -1;
  103. calendar.setTime(curDate);
  104. String curYearAndMonth = calendar.get(Calendar.YEAR) + "" + calendar.get(Calendar.MONTH);
  105. calendar.setTime(today);
  106. String todayYearAndMonth = calendar.get(Calendar.YEAR) + "" + calendar.get(Calendar.MONTH);
  107. if (curYearAndMonth.equals(todayYearAndMonth)) {
  108. int todayNumber = calendar.get(Calendar.DAY_OF_MONTH);
  109. todayIndex = curStartIndex + todayNumber - 1;
  110. }
  111. for (int i = 0; i < 42; i++) {
  112. int color = surface.textColor;
  113. if (isLastMonth(i)) {
  114. color = surface.borderColor;
  115. } else if (isNextMonth(i)) {
  116. color = surface.borderColor;
  117. }
  118. if (todayIndex != -1 && i == todayIndex) {
  119. color = surface.todayNumberColor;
  120. }
  121. drawCellText(canvas, i, date[i] + "", color);
  122. }
  123. super.onDraw(canvas);
  124. }
  125. private void calculateDate() {
  126. calendar.setTime(curDate);
  127. calendar.set(Calendar.DAY_OF_MONTH, 1);
  128. int dayInWeek = calendar.get(Calendar.DAY_OF_WEEK);
  129. Log.d(TAG, "day in week:" + dayInWeek);
  130. int monthStart = dayInWeek;
  131. if (monthStart == 1) {
  132. monthStart = 8;
  133. }
  134. monthStart -= 1; // 以日为开头-1,以星期一为开头-2
  135. curStartIndex = monthStart;
  136. date[monthStart] = 1;
  137. // last month
  138. if (monthStart > 0) {
  139. calendar.set(Calendar.DAY_OF_MONTH, 0);
  140. int dayInmonth = calendar.get(Calendar.DAY_OF_MONTH);
  141. for (int i = monthStart - 1; i >= 0; i--) {
  142. date[i] = dayInmonth;
  143. dayInmonth--;
  144. }
  145. calendar.set(Calendar.DAY_OF_MONTH, date[0]);
  146. }
  147. showFirstDate = calendar.getTime();
  148. // this month
  149. calendar.setTime(curDate);
  150. calendar.add(Calendar.MONTH, 1);
  151. calendar.set(Calendar.DAY_OF_MONTH, 0);
  152. // Log.d(TAG, "m:" + calendar.get(Calendar.MONTH) + " d:" +
  153. // calendar.get(Calendar.DAY_OF_MONTH));
  154. int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
  155. for (int i = 1; i < monthDay; i++) {
  156. date[monthStart + i] = i + 1;
  157. }
  158. curEndIndex = monthStart + monthDay;
  159. // next month
  160. for (int i = monthStart + monthDay; i < 42; i++) {
  161. date[i] = i - (monthStart + monthDay) + 1;
  162. }
  163. if (curEndIndex < 42) {
  164. // 显示了下一月的
  165. calendar.add(Calendar.DAY_OF_MONTH, 1);
  166. }
  167. calendar.set(Calendar.DAY_OF_MONTH, date[41]);
  168. showLastDate = calendar.getTime();
  169. }
  170. /**
  171. *
  172. * @param canvas
  173. * @param index
  174. * @param text
  175. */
  176. private void drawCellText(Canvas canvas, int index, String text, int color) {
  177. int x = getXByIndex(index);
  178. int y = getYByIndex(index);
  179. surface.datePaint.setColor(color);
  180. float cellY = surface.monthHeight + surface.weekHeight + (y - 1) * surface.cellHeight + surface.cellHeight * 3 / 4f;
  181. float cellX = (surface.cellWidth * (x - 1)) + (surface.cellWidth - surface.datePaint.measureText(text)) / 2f;
  182. canvas.drawText(text, cellX, cellY, surface.datePaint);
  183. }
  184. /**
  185. *
  186. * @param canvas
  187. * @param index
  188. * @param color
  189. */
  190. private void drawCellBg(Canvas canvas, int index, int color) {
  191. int x = getXByIndex(index);
  192. int y = getYByIndex(index);
  193. surface.cellBgPaint.setColor(color);
  194. float left = surface.cellWidth * (x - 1) + surface.borderWidth;
  195. float top = surface.monthHeight + surface.weekHeight + (y - 1) * surface.cellHeight + surface.borderWidth;
  196. canvas.drawRect(left, top, left + surface.cellWidth - surface.borderWidth, top + surface.cellHeight - surface.borderWidth, surface.cellBgPaint);
  197. }
  198. private void drawDownOrSelectedBg(Canvas canvas) {
  199. // down and not up
  200. if (downDate != null) {
  201. drawCellBg(canvas, downIndex, surface.cellDownColor);
  202. }
  203. // selected bg color
  204. if (!selectedEndDate.before(showFirstDate) && !selectedStartDate.after(showLastDate)) {
  205. int[] section = new int[] { -1, -1 };
  206. calendar.setTime(curDate);
  207. calendar.add(Calendar.MONTH, -1);
  208. findSelectedIndex(0, curStartIndex, calendar, section);
  209. if (section[1] == -1) {
  210. calendar.setTime(curDate);
  211. findSelectedIndex(curStartIndex, curEndIndex, calendar, section);
  212. }
  213. if (section[1] == -1) {
  214. calendar.setTime(curDate);
  215. calendar.add(Calendar.MONTH, 1);
  216. findSelectedIndex(curEndIndex, 42, calendar, section);
  217. }
  218. if (section[0] == -1) {
  219. section[0] = 0;
  220. }
  221. if (section[1] == -1) {
  222. section[1] = 41;
  223. }
  224. for (int i = section[0]; i <= section[1]; i++) {
  225. drawCellBg(canvas, i, surface.cellSelectedColor);
  226. }
  227. }
  228. }
  229. private void findSelectedIndex(int startIndex, int endIndex, Calendar calendar, int[] section) {
  230. for (int i = startIndex; i < endIndex; i++) {
  231. calendar.set(Calendar.DAY_OF_MONTH, date[i]);
  232. Date temp = calendar.getTime();
  233. // Log.d(TAG, "temp:" + temp.toLocaleString());
  234. if (temp.compareTo(selectedStartDate) == 0) {
  235. section[0] = i;
  236. }
  237. if (temp.compareTo(selectedEndDate) == 0) {
  238. section[1] = i;
  239. return;
  240. }
  241. }
  242. }
  243. public Date getSelectedStartDate() {
  244. return selectedStartDate;
  245. }
  246. public Date getSelectedEndDate() {
  247. return selectedEndDate;
  248. }
  249. private boolean isLastMonth(int i) {
  250. if (i < curStartIndex) {
  251. return true;
  252. }
  253. return false;
  254. }
  255. private boolean isNextMonth(int i) {
  256. if (i >= curEndIndex) {
  257. return true;
  258. }
  259. return false;
  260. }
  261. private int getXByIndex(int i) {
  262. return i % 7 + 1; // 1 2 3 4 5 6 7
  263. }
  264. private int getYByIndex(int i) {
  265. return i / 7 + 1; // 1 2 3 4 5 6
  266. }
  267. // 获得当前应该显示的年月
  268. public String getYearAndmonth() {
  269. calendar.setTime(curDate);
  270. int year = calendar.get(Calendar.YEAR);
  271. int month = calendar.get(Calendar.MONTH);
  272. return year + "-" + surface.monthText[month];
  273. }
  274. // 上一月
  275. public String clickLeftMonth() {
  276. calendar.setTime(curDate);
  277. calendar.add(Calendar.MONTH, -1);
  278. curDate = calendar.getTime();
  279. invalidate();
  280. return getYearAndmonth();
  281. }
  282. // 下一月
  283. public String clickRightMonth() {
  284. calendar.setTime(curDate);
  285. calendar.add(Calendar.MONTH, 1);
  286. curDate = calendar.getTime();
  287. invalidate();
  288. return getYearAndmonth();
  289. }
  290. private void setSelectedDateByCoor(float x, float y) {
  291. // change month
  292. // if (y < surface.monthHeight) {
  293. // // pre month
  294. // if (x < surface.monthChangeWidth) {
  295. // calendar.setTime(curDate);
  296. // calendar.add(Calendar.MONTH, -1);
  297. // curDate = calendar.getTime();
  298. // }
  299. // // next month
  300. // else if (x > surface.width - surface.monthChangeWidth) {
  301. // calendar.setTime(curDate);
  302. // calendar.add(Calendar.MONTH, 1);
  303. // curDate = calendar.getTime();
  304. // }
  305. // }
  306. // cell click down
  307. if (y > surface.monthHeight + surface.weekHeight) {
  308. int m = (int) (Math.floor(x / surface.cellWidth) + 1);
  309. int n = (int) (Math.floor((y - (surface.monthHeight + surface.weekHeight)) / Float.valueOf(surface.cellHeight)) + 1);
  310. downIndex = (n - 1) * 7 + m - 1;
  311. Log.d(TAG, "downIndex:" + downIndex);
  312. calendar.setTime(curDate);
  313. if (isLastMonth(downIndex)) {
  314. calendar.add(Calendar.MONTH, -1);
  315. } else if (isNextMonth(downIndex)) {
  316. calendar.add(Calendar.MONTH, 1);
  317. }
  318. calendar.set(Calendar.DAY_OF_MONTH, date[downIndex]);
  319. downDate = calendar.getTime();
  320. }
  321. invalidate();
  322. }
  323. @Override
  324. public boolean onTouch(View v, MotionEvent event) {
  325. switch (event.getAction()) {
  326. case MotionEvent.ACTION_DOWN:
  327. setSelectedDateByCoor(event.getX(), event.getY());
  328. break;
  329. case MotionEvent.ACTION_UP:
  330. if (downDate != null) {
  331. // if (!completed) {
  332. // if (downDate.before(selectedStartDate)) {
  333. // selectedEndDate = selectedStartDate;
  334. // selectedStartDate = downDate;
  335. // } else {
  336. // selectedEndDate = downDate;
  337. // }
  338. // completed = true;
  339. // } else {
  340. // selectedStartDate = selectedEndDate = downDate;
  341. // completed = false;
  342. // }
  343. selectedStartDate = selectedEndDate = downDate;
  344. // 响应监听事件
  345. onItemClickListener.OnItemClick(selectedStartDate);
  346. // Log.d(TAG, "downdate:" + downDate.toLocaleString());
  347. // Log.d(TAG, "start:" + selectedStartDate.toLocaleString());
  348. // Log.d(TAG, "end:" + selectedEndDate.toLocaleString());
  349. downDate = null;
  350. invalidate();
  351. }
  352. break;
  353. }
  354. return true;
  355. }
  356. // 给控件设置监听事件
  357. public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
  358. this.onItemClickListener = onItemClickListener;
  359. }
  360. // 监听接口
  361. public interface OnItemClickListener {
  362. void OnItemClick(Date date);
  363. }
  364. /**
  365. *
  366. * 1. 布局尺寸 2. 文字颜色,大小 3. 当前日期的颜色,选择的日期颜色
  367. */
  368. private class Surface {
  369. public float density;
  370. public int width; // 整个控件的宽度
  371. public int height; // 整个控件的高度
  372. public float monthHeight; // 显示月的高度
  373. // public float monthChangeWidth; // 上一月、下一月按钮宽度
  374. public float weekHeight; // 显示星期的高度
  375. public float cellWidth; // 日期方框宽度
  376. public float cellHeight; // 日期方框高度
  377. public float borderWidth;
  378. public int bgColor = Color.parseColor("#FFFFFF");
  379. private int textColor = Color.BLACK;
  380. // private int textColorUnimportant = Color.parseColor("#666666");
  381. private int btnColor = Color.parseColor("#666666");
  382. private int borderColor = Color.parseColor("#CCCCCC");
  383. public int todayNumberColor = Color.RED;
  384. public int cellDownColor = Color.parseColor("#CCFFFF");
  385. public int cellSelectedColor = Color.parseColor("#99CCFF");
  386. public Paint borderPaint;
  387. public Paint monthPaint;
  388. public Paint weekPaint;
  389. public Paint datePaint;
  390. public Paint monthChangeBtnPaint;
  391. public Paint cellBgPaint;
  392. public Path boxPath; // 边框路径
  393. // public Path preMonthBtnPath; // 上一月按钮三角形
  394. // public Path nextMonthBtnPath; // 下一月按钮三角形
  395. public String[] weekText = { "日", "一", "二", "三", "四", "五", "六" };
  396. public String[] monthText = { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
  397. public void init() {
  398. float temp = height / 7f;
  399. monthHeight = 0;// (float) ((temp + temp * 0.3f) * 0.6);
  400. // monthChangeWidth = monthHeight * 1.5f;
  401. weekHeight = (float) ((temp + temp * 0.3f) * 0.7);
  402. cellHeight = (height - monthHeight - weekHeight) / 6f;
  403. cellWidth = width / 7f;
  404. borderPaint = new Paint();
  405. borderPaint.setColor(borderColor);
  406. borderPaint.setStyle(Paint.Style.STROKE);
  407. borderWidth = (float) (0.5 * density);
  408. // Log.d(TAG, "borderwidth:" + borderWidth);
  409. borderWidth = borderWidth < 1 ? 1 : borderWidth;
  410. borderPaint.setStrokeWidth(borderWidth);
  411. monthPaint = new Paint();
  412. monthPaint.setColor(textColor);
  413. monthPaint.setAntiAlias(true);
  414. float textSize = cellHeight * 0.4f;
  415. Log.d(TAG, "text size:" + textSize);
  416. monthPaint.setTextSize(textSize);
  417. monthPaint.setTypeface(Typeface.DEFAULT_BOLD);
  418. weekPaint = new Paint();
  419. weekPaint.setColor(textColor);
  420. weekPaint.setAntiAlias(true);
  421. float weekTextSize = weekHeight * 0.6f;
  422. weekPaint.setTextSize(weekTextSize);
  423. weekPaint.setTypeface(Typeface.DEFAULT_BOLD);
  424. datePaint = new Paint();
  425. datePaint.setColor(textColor);
  426. datePaint.setAntiAlias(true);
  427. float cellTextSize = cellHeight * 0.5f;
  428. datePaint.setTextSize(cellTextSize);
  429. datePaint.setTypeface(Typeface.DEFAULT_BOLD);
  430. boxPath = new Path();
  431. // boxPath.addRect(0, 0, width, height, Direction.CW);
  432. // boxPath.moveTo(0, monthHeight);
  433. boxPath.rLineTo(width, 0);
  434. boxPath.moveTo(0, monthHeight + weekHeight);
  435. boxPath.rLineTo(width, 0);
  436. for (int i = 1; i < 6; i++) {
  437. boxPath.moveTo(0, monthHeight + weekHeight + i * cellHeight);
  438. boxPath.rLineTo(width, 0);
  439. boxPath.moveTo(i * cellWidth, monthHeight);
  440. boxPath.rLineTo(0, height - monthHeight);
  441. }
  442. boxPath.moveTo(6 * cellWidth, monthHeight);
  443. boxPath.rLineTo(0, height - monthHeight);
  444. // preMonthBtnPath = new Path();
  445. // int btnHeight = (int) (monthHeight * 0.6f);
  446. // preMonthBtnPath.moveTo(monthChangeWidth / 2f, monthHeight / 2f);
  447. // preMonthBtnPath.rLineTo(btnHeight / 2f, -btnHeight / 2f);
  448. // preMonthBtnPath.rLineTo(0, btnHeight);
  449. // preMonthBtnPath.close();
  450. // nextMonthBtnPath = new Path();
  451. // nextMonthBtnPath.moveTo(width - monthChangeWidth / 2f,
  452. // monthHeight / 2f);
  453. // nextMonthBtnPath.rLineTo(-btnHeight / 2f, -btnHeight / 2f);
  454. // nextMonthBtnPath.rLineTo(0, btnHeight);
  455. // nextMonthBtnPath.close();
  456. monthChangeBtnPaint = new Paint();
  457. monthChangeBtnPaint.setAntiAlias(true);
  458. monthChangeBtnPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  459. monthChangeBtnPaint.setColor(btnColor);
  460. cellBgPaint = new Paint();
  461. cellBgPaint.setAntiAlias(true);
  462. cellBgPaint.setStyle(Paint.Style.FILL);
  463. cellBgPaint.setColor(cellSelectedColor);
  464. }
  465. }
  466. }

2、承载的Activity
  1. package com.nh.activity;
  2. import java.util.Date;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.text.format.DateFormat;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.view.Window;
  10. import android.widget.TextView;
  11. import com.hugegis.whwypt.pda.R;
  12. import com.nh.view.CalendarView;
  13. import com.nh.view.CalendarView.OnItemClickListener;
  14. public class DateDialogActivity extends Activity implements OnClickListener {
  15. private CalendarView calendar;
  16. private TextView calendarLeft;
  17. private TextView calendarRight;
  18. private TextView calendarCenter;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. requestWindowFeature(Window.FEATURE_NO_TITLE);
  23. setContentView(R.layout.activity_date_dialog);
  24. intiview();
  25. }
  26. // 初始化控件
  27. private void intiview() {
  28. // 获取日历控件对象
  29. calendar = (CalendarView) findViewById(R.id.calendar);
  30. // 设置控件监听,可以监听到点击的每一天(大家也可以在控件中自行设定)
  31. calendar.setOnItemClickListener(new calendarItemClickListener());
  32. // 切换月份
  33. calendarLeft = (TextView) findViewById(R.id.calendarLeft);
  34. calendarLeft.setOnClickListener(this);
  35. calendarRight = (TextView) findViewById(R.id.calendarRight);
  36. calendarRight.setOnClickListener(this);
  37. // 显示月份
  38. calendarCenter = (TextView) findViewById(R.id.calendarCenter);
  39. // 获取日历中年月 ya[0]为年,ya[1]为月(格式大家可以自行在日历控件中改)
  40. String[] ya = calendar.getYearAndmonth().split("-");
  41. calendarCenter.setText(ya[1]);
  42. Intent intent = new Intent();
  43. setResult(1003, intent);
  44. }
  45. class calendarItemClickListener implements OnItemClickListener {
  46. @Override
  47. public void OnItemClick(Date date) {
  48. String[] startdate = gmt_utc(date).split("T");
  49. Intent intent = new Intent();
  50. intent.putExtra("date", startdate[0]);
  51. intent.putExtra("return", true);
  52. setResult(1003, intent);
  53. finish();
  54. }
  55. }
  56. // 时间转换
  57. String gmt_utc(Date date) {
  58. return (String) DateFormat.format("yyyy'-'MM'-'dd'T'kk':'mm':'ss'Z'", date);
  59. }
  60. @Override
  61. public void onClick(View v) {
  62. switch (v.getId()) {
  63. case R.id.calendarLeft:
  64. // 点击上一月 同样返回年月
  65. String leftYearAndmonth = calendar.clickLeftMonth();
  66. String[] lya = leftYearAndmonth.split("-");
  67. calendarCenter.setText(lya[1]);
  68. break;
  69. case R.id.calendarRight:
  70. // 点击下一月
  71. String rightYearAndmonth = calendar.clickRightMonth();
  72. String[] rya = rightYearAndmonth.split("-");
  73. calendarCenter.setText(rya[1]);
  74. break;
  75. default:
  76. break;
  77. }
  78. }
  79. }
3、布局文件

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. style="@style/AlertDialogCustom"
  4. android:layout_width="wrap_content"
  5. android:layout_height="wrap_content"
  6. tools:context="${relativePackage}.${activityClass}" >
  7. <RelativeLayout
  8. android:id="@+id/layout_calendar"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_alignParentLeft="true"
  12. android:layout_alignParentTop="true"
  13. android:background="@drawable/bg_date_style"
  14. android:visibility="visible" >
  15. <TextView
  16. android:id="@+id/calendarLeft"
  17. android:layout_width="60dp"
  18. android:layout_height="60dp"
  19. android:layout_alignParentLeft="true"
  20. android:background="@null"
  21. android:contentDescription="@null"
  22. android:gravity="center"
  23. android:text="<"
  24. android:textColor="@android:color/white"
  25. android:textSize="40sp" />
  26. <com.nh.view.CalendarView
  27. android:id="@+id/calendar"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:layout_below="@+id/calendarLeft"
  31. android:layout_centerHorizontal="true" />
  32. <TextView
  33. android:id="@+id/calendarRight"
  34. android:layout_width="60dp"
  35. android:layout_height="60dp"
  36. android:layout_alignParentTop="true"
  37. android:layout_alignRight="@+id/calendar"
  38. android:background="@null"
  39. android:contentDescription="@null"
  40. android:gravity="center"
  41. android:text=">"
  42. android:textColor="@android:color/white"
  43. android:textSize="40sp" />
  44. <TextView
  45. android:id="@+id/calendarCenter"
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:layout_alignBaseline="@+id/calendarLeft"
  49. android:layout_alignBottom="@+id/calendarLeft"
  50. android:layout_centerHorizontal="true"
  51. android:text="@string/app_name"
  52. android:textColor="@android:color/black"
  53. android:textSize="30sp"
  54. android:textStyle="bold" />
  55. </RelativeLayout>
  56. </RelativeLayout>
3、接收日历返回值

  1. @Override
  2. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  3. super.onActivityResult(requestCode, resultCode, data);
  4. // 日历
  5. if (resultCode == 1003) {
  6. if (false == data.getBooleanExtra("return", false)) {
  7. return;
  8. }
  9. switch (requestCode) {
  10. case 1001:
  11. // 开始时间
  12. String startdateString = data.getStringExtra("date");
  13. if (judgeDate(startdateString, requestCode)) {
  14. tv_start_date.setText(startdateString);
  15. } else {
  16. tv_start_date.setText(null);
  17. }
  18. break;
  19. case 1002:
  20. // 结束时间
  21. String enddateString = data.getStringExtra("date");
  22. if (judgeDate(enddateString, requestCode)) {
  23. tv_end_date.setText(enddateString);
  24. } else {
  25. tv_end_date.setText(null);
  26. }
  27. break;
  28. }
  29. }
  30. }


虽然功能过于麻烦,不过感觉效果还是不错的

  1. import java.util.Calendar;
  2. import java.util.Date;
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.graphics.Color;
  6. import android.graphics.Paint;
  7. import android.graphics.Path;
  8. import android.graphics.Typeface;
  9. import android.util.AttributeSet;
  10. import android.util.Log;
  11. import android.view.MotionEvent;
  12. import android.view.View;
  13. public class CalendarView extends View implements View.OnTouchListener {
  14. private final static String TAG = "anCalendar";
  15. private Date selectedStartDate;
  16. private Date selectedEndDate;
  17. private Date curDate; // 当前日历显示的月
  18. private Date today; // 今天的日期文字显示红色
  19. private Date downDate; // 手指按下状态时临时日期
  20. private Date showFirstDate, showLastDate; // 日历显示的第一个日期和最后一个日期
  21. private int downIndex; // 按下的格子索引
  22. private Calendar calendar;
  23. private Surface surface;
  24. private int[] date = new int[42]; // 日历显示数字
  25. private int curStartIndex, curEndIndex; // 当前显示的日历起始的索引
  26. // private boolean completed = false; // 为false表示只选择了开始日期,true表示结束日期也选择了
  27. // 给控件设置监听事件
  28. private OnItemClickListener onItemClickListener;
  29. public CalendarView(Context context) {
  30. super(context);
  31. init();
  32. }
  33. public CalendarView(Context context, AttributeSet attrs) {
  34. super(context, attrs);
  35. init();
  36. }
  37. private void init() {
  38. curDate = selectedStartDate = selectedEndDate = today = new Date();
  39. calendar = Calendar.getInstance();
  40. calendar.setTime(curDate);
  41. surface = new Surface();
  42. surface.density = getResources().getDisplayMetrics().density;
  43. setBackgroundColor(surface.bgColor);
  44. setOnTouchListener(this);
  45. }
  46. @Override
  47. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  48. surface.width = getResources().getDisplayMetrics().widthPixels * 4 / 5;
  49. surface.height = (int) (getResources().getDisplayMetrics().heightPixels * 2 / 5);
  50. // if (View.MeasureSpec.getMode(widthMeasureSpec) ==
  51. // View.MeasureSpec.EXACTLY) {
  52. // surface.width = View.MeasureSpec.getSize(widthMeasureSpec);
  53. // }
  54. // if (View.MeasureSpec.getMode(heightMeasureSpec) ==
  55. // View.MeasureSpec.EXACTLY) {
  56. // surface.height = View.MeasureSpec.getSize(heightMeasureSpec);
  57. // }
  58. widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(surface.width, View.MeasureSpec.EXACTLY);
  59. heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(surface.height, View.MeasureSpec.EXACTLY);
  60. setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
  61. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  62. }
  63. @Override
  64. protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  65. Log.d(TAG, "[onLayout] changed:" + (changed ? "new size" : "not change") + " left:" + left + " top:" + top + " right:" + right + " bottom:" + bottom);
  66. if (changed) {
  67. surface.init();
  68. }
  69. super.onLayout(changed, left, top, right, bottom);
  70. }
  71. @Override
  72. protected void onDraw(Canvas canvas) {
  73. Log.d(TAG, "onDraw");
  74. // 画框
  75. canvas.drawPath(surface.boxPath, surface.borderPaint);
  76. // 年月
  77. // String monthText = getYearAndmonth();
  78. // float textWidth = surface.monthPaint.measureText(monthText);
  79. // canvas.drawText(monthText, (surface.width - textWidth) / 2f,
  80. // surface.monthHeight * 3 / 4f, surface.monthPaint);
  81. // 上一月/下一月
  82. // canvas.drawPath(surface.preMonthBtnPath,
  83. // surface.monthChangeBtnPaint);
  84. // canvas.drawPath(surface.nextMonthBtnPath,
  85. // surface.monthChangeBtnPaint);
  86. // 星期
  87. float weekTextY = surface.monthHeight + surface.weekHeight * 3 / 4f;
  88. // 星期背景
  89. // surface.cellBgPaint.setColor(surface.textColor);
  90. // canvas.drawRect(surface.weekHeight, surface.width,
  91. // surface.weekHeight, surface.width, surface.cellBgPaint);
  92. for (int i = 0; i < surface.weekText.length; i++) {
  93. float weekTextX = i * surface.cellWidth + (surface.cellWidth - surface.weekPaint.measureText(surface.weekText[i])) / 2f;
  94. canvas.drawText(surface.weekText[i], weekTextX, weekTextY, surface.weekPaint);
  95. }
  96. // 计算日期
  97. calculateDate();
  98. // 按下状态,选择状态背景色
  99. drawDownOrSelectedBg(canvas);
  100. // write date number
  101. // today index
  102. int todayIndex = -1;
  103. calendar.setTime(curDate);
  104. String curYearAndMonth = calendar.get(Calendar.YEAR) + "" + calendar.get(Calendar.MONTH);
  105. calendar.setTime(today);
  106. String todayYearAndMonth = calendar.get(Calendar.YEAR) + "" + calendar.get(Calendar.MONTH);
  107. if (curYearAndMonth.equals(todayYearAndMonth)) {
  108. int todayNumber = calendar.get(Calendar.DAY_OF_MONTH);
  109. todayIndex = curStartIndex + todayNumber - 1;
  110. }
  111. for (int i = 0; i < 42; i++) {
  112. int color = surface.textColor;
  113. if (isLastMonth(i)) {
  114. color = surface.borderColor;
  115. } else if (isNextMonth(i)) {
  116. color = surface.borderColor;
  117. }
  118. if (todayIndex != -1 && i == todayIndex) {
  119. color = surface.todayNumberColor;
  120. }
  121. drawCellText(canvas, i, date[i] + "", color);
  122. }
  123. super.onDraw(canvas);
  124. }
  125. private void calculateDate() {
  126. calendar.setTime(curDate);
  127. calendar.set(Calendar.DAY_OF_MONTH, 1);
  128. int dayInWeek = calendar.get(Calendar.DAY_OF_WEEK);
  129. Log.d(TAG, "day in week:" + dayInWeek);
  130. int monthStart = dayInWeek;
  131. if (monthStart == 1) {
  132. monthStart = 8;
  133. }
  134. monthStart -= 1; // 以日为开头-1,以星期一为开头-2
  135. curStartIndex = monthStart;
  136. date[monthStart] = 1;
  137. // last month
  138. if (monthStart > 0) {
  139. calendar.set(Calendar.DAY_OF_MONTH, 0);
  140. int dayInmonth = calendar.get(Calendar.DAY_OF_MONTH);
  141. for (int i = monthStart - 1; i >= 0; i--) {
  142. date[i] = dayInmonth;
  143. dayInmonth--;
  144. }
  145. calendar.set(Calendar.DAY_OF_MONTH, date[0]);
  146. }
  147. showFirstDate = calendar.getTime();
  148. // this month
  149. calendar.setTime(curDate);
  150. calendar.add(Calendar.MONTH, 1);
  151. calendar.set(Calendar.DAY_OF_MONTH, 0);
  152. // Log.d(TAG, "m:" + calendar.get(Calendar.MONTH) + " d:" +
  153. // calendar.get(Calendar.DAY_OF_MONTH));
  154. int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
  155. for (int i = 1; i < monthDay; i++) {
  156. date[monthStart + i] = i + 1;
  157. }
  158. curEndIndex = monthStart + monthDay;
  159. // next month
  160. for (int i = monthStart + monthDay; i < 42; i++) {
  161. date[i] = i - (monthStart + monthDay) + 1;
  162. }
  163. if (curEndIndex < 42) {
  164. // 显示了下一月的
  165. calendar.add(Calendar.DAY_OF_MONTH, 1);
  166. }
  167. calendar.set(Calendar.DAY_OF_MONTH, date[41]);
  168. showLastDate = calendar.getTime();
  169. }
  170. /**
  171. *
  172. * @param canvas
  173. * @param index
  174. * @param text
  175. */
  176. private void drawCellText(Canvas canvas, int index, String text, int color) {
  177. int x = getXByIndex(index);
  178. int y = getYByIndex(index);
  179. surface.datePaint.setColor(color);
  180. float cellY = surface.monthHeight + surface.weekHeight + (y - 1) * surface.cellHeight + surface.cellHeight * 3 / 4f;
  181. float cellX = (surface.cellWidth * (x - 1)) + (surface.cellWidth - surface.datePaint.measureText(text)) / 2f;
  182. canvas.drawText(text, cellX, cellY, surface.datePaint);
  183. }
  184. /**
  185. *
  186. * @param canvas
  187. * @param index
  188. * @param color
  189. */
  190. private void drawCellBg(Canvas canvas, int index, int color) {
  191. int x = getXByIndex(index);
  192. int y = getYByIndex(index);
  193. surface.cellBgPaint.setColor(color);
  194. float left = surface.cellWidth * (x - 1) + surface.borderWidth;
  195. float top = surface.monthHeight + surface.weekHeight + (y - 1) * surface.cellHeight + surface.borderWidth;
  196. canvas.drawRect(left, top, left + surface.cellWidth - surface.borderWidth, top + surface.cellHeight - surface.borderWidth, surface.cellBgPaint);
  197. }
  198. private void drawDownOrSelectedBg(Canvas canvas) {
  199. // down and not up
  200. if (downDate != null) {
  201. drawCellBg(canvas, downIndex, surface.cellDownColor);
  202. }
  203. // selected bg color
  204. if (!selectedEndDate.before(showFirstDate) && !selectedStartDate.after(showLastDate)) {
  205. int[] section = new int[] { -1, -1 };
  206. calendar.setTime(curDate);
  207. calendar.add(Calendar.MONTH, -1);
  208. findSelectedIndex(0, curStartIndex, calendar, section);
  209. if (section[1] == -1) {
  210. calendar.setTime(curDate);
  211. findSelectedIndex(curStartIndex, curEndIndex, calendar, section);
  212. }
  213. if (section[1] == -1) {
  214. calendar.setTime(curDate);
  215. calendar.add(Calendar.MONTH, 1);
  216. findSelectedIndex(curEndIndex, 42, calendar, section);
  217. }
  218. if (section[0] == -1) {
  219. section[0] = 0;
  220. }
  221. if (section[1] == -1) {
  222. section[1] = 41;
  223. }
  224. for (int i = section[0]; i <= section[1]; i++) {
  225. drawCellBg(canvas, i, surface.cellSelectedColor);
  226. }
  227. }
  228. }
  229. private void findSelectedIndex(int startIndex, int endIndex, Calendar calendar, int[] section) {
  230. for (int i = startIndex; i < endIndex; i++) {
  231. calendar.set(Calendar.DAY_OF_MONTH, date[i]);
  232. Date temp = calendar.getTime();
  233. // Log.d(TAG, "temp:" + temp.toLocaleString());
  234. if (temp.compareTo(selectedStartDate) == 0) {
  235. section[0] = i;
  236. }
  237. if (temp.compareTo(selectedEndDate) == 0) {
  238. section[1] = i;
  239. return;
  240. }
  241. }
  242. }
  243. public Date getSelectedStartDate() {
  244. return selectedStartDate;
  245. }
  246. public Date getSelectedEndDate() {
  247. return selectedEndDate;
  248. }
  249. private boolean isLastMonth(int i) {
  250. if (i < curStartIndex) {
  251. return true;
  252. }
  253. return false;
  254. }
  255. private boolean isNextMonth(int i) {
  256. if (i >= curEndIndex) {
  257. return true;
  258. }
  259. return false;
  260. }
  261. private int getXByIndex(int i) {
  262. return i % 7 + 1; // 1 2 3 4 5 6 7
  263. }
  264. private int getYByIndex(int i) {
  265. return i / 7 + 1; // 1 2 3 4 5 6
  266. }
  267. // 获得当前应该显示的年月
  268. public String getYearAndmonth() {
  269. calendar.setTime(curDate);
  270. int year = calendar.get(Calendar.YEAR);
  271. int month = calendar.get(Calendar.MONTH);
  272. return year + "-" + surface.monthText[month];
  273. }
  274. // 上一月
  275. public String clickLeftMonth() {
  276. calendar.setTime(curDate);
  277. calendar.add(Calendar.MONTH, -1);
  278. curDate = calendar.getTime();
  279. invalidate();
  280. return getYearAndmonth();
  281. }
  282. // 下一月
  283. public String clickRightMonth() {
  284. calendar.setTime(curDate);
  285. calendar.add(Calendar.MONTH, 1);
  286. curDate = calendar.getTime();
  287. invalidate();
  288. return getYearAndmonth();
  289. }
  290. private void setSelectedDateByCoor(float x, float y) {
  291. // change month
  292. // if (y < surface.monthHeight) {
  293. // // pre month
  294. // if (x < surface.monthChangeWidth) {
  295. // calendar.setTime(curDate);
  296. // calendar.add(Calendar.MONTH, -1);
  297. // curDate = calendar.getTime();
  298. // }
  299. // // next month
  300. // else if (x > surface.width - surface.monthChangeWidth) {
  301. // calendar.setTime(curDate);
  302. // calendar.add(Calendar.MONTH, 1);
  303. // curDate = calendar.getTime();
  304. // }
  305. // }
  306. // cell click down
  307. if (y > surface.monthHeight + surface.weekHeight) {
  308. int m = (int) (Math.floor(x / surface.cellWidth) + 1);
  309. int n = (int) (Math.floor((y - (surface.monthHeight + surface.weekHeight)) / Float.valueOf(surface.cellHeight)) + 1);
  310. downIndex = (n - 1) * 7 + m - 1;
  311. Log.d(TAG, "downIndex:" + downIndex);
  312. calendar.setTime(curDate);
  313. if (isLastMonth(downIndex)) {
  314. calendar.add(Calendar.MONTH, -1);
  315. } else if (isNextMonth(downIndex)) {
  316. calendar.add(Calendar.MONTH, 1);
  317. }
  318. calendar.set(Calendar.DAY_OF_MONTH, date[downIndex]);
  319. downDate = calendar.getTime();
  320. }
  321. invalidate();
  322. }
  323. @Override
  324. public boolean onTouch(View v, MotionEvent event) {
  325. switch (event.getAction()) {
  326. case MotionEvent.ACTION_DOWN:
  327. setSelectedDateByCoor(event.getX(), event.getY());
  328. break;
  329. case MotionEvent.ACTION_UP:
  330. if (downDate != null) {
  331. // if (!completed) {
  332. // if (downDate.before(selectedStartDate)) {
  333. // selectedEndDate = selectedStartDate;
  334. // selectedStartDate = downDate;
  335. // } else {
  336. // selectedEndDate = downDate;
  337. // }
  338. // completed = true;
  339. // } else {
  340. // selectedStartDate = selectedEndDate = downDate;
  341. // completed = false;
  342. // }
  343. selectedStartDate = selectedEndDate = downDate;
  344. // 响应监听事件
  345. onItemClickListener.OnItemClick(selectedStartDate);
  346. // Log.d(TAG, "downdate:" + downDate.toLocaleString());
  347. // Log.d(TAG, "start:" + selectedStartDate.toLocaleString());
  348. // Log.d(TAG, "end:" + selectedEndDate.toLocaleString());
  349. downDate = null;
  350. invalidate();
  351. }
  352. break;
  353. }
  354. return true;
  355. }
  356. // 给控件设置监听事件
  357. public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
  358. this.onItemClickListener = onItemClickListener;
  359. }
  360. // 监听接口
  361. public interface OnItemClickListener {
  362. void OnItemClick(Date date);
  363. }
  364. /**
  365. *
  366. * 1. 布局尺寸 2. 文字颜色,大小 3. 当前日期的颜色,选择的日期颜色
  367. */
  368. private class Surface {
  369. public float density;
  370. public int width; // 整个控件的宽度
  371. public int height; // 整个控件的高度
  372. public float monthHeight; // 显示月的高度
  373. // public float monthChangeWidth; // 上一月、下一月按钮宽度
  374. public float weekHeight; // 显示星期的高度
  375. public float cellWidth; // 日期方框宽度
  376. public float cellHeight; // 日期方框高度
  377. public float borderWidth;
  378. public int bgColor = Color.parseColor("#FFFFFF");
  379. private int textColor = Color.BLACK;
  380. // private int textColorUnimportant = Color.parseColor("#666666");
  381. private int btnColor = Color.parseColor("#666666");
  382. private int borderColor = Color.parseColor("#CCCCCC");
  383. public int todayNumberColor = Color.RED;
  384. public int cellDownColor = Color.parseColor("#CCFFFF");
  385. public int cellSelectedColor = Color.parseColor("#99CCFF");
  386. public Paint borderPaint;
  387. public Paint monthPaint;
  388. public Paint weekPaint;
  389. public Paint datePaint;
  390. public Paint monthChangeBtnPaint;
  391. public Paint cellBgPaint;
  392. public Path boxPath; // 边框路径
  393. // public Path preMonthBtnPath; // 上一月按钮三角形
  394. // public Path nextMonthBtnPath; // 下一月按钮三角形
  395. public String[] weekText = { "日", "一", "二", "三", "四", "五", "六" };
  396. public String[] monthText = { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
  397. public void init() {
  398. float temp = height / 7f;
  399. monthHeight = 0;// (float) ((temp + temp * 0.3f) * 0.6);
  400. // monthChangeWidth = monthHeight * 1.5f;
  401. weekHeight = (float) ((temp + temp * 0.3f) * 0.7);
  402. cellHeight = (height - monthHeight - weekHeight) / 6f;
  403. cellWidth = width / 7f;
  404. borderPaint = new Paint();
  405. borderPaint.setColor(borderColor);
  406. borderPaint.setStyle(Paint.Style.STROKE);
  407. borderWidth = (float) (0.5 * density);
  408. // Log.d(TAG, "borderwidth:" + borderWidth);
  409. borderWidth = borderWidth < 1 ? 1 : borderWidth;
  410. borderPaint.setStrokeWidth(borderWidth);
  411. monthPaint = new Paint();
  412. monthPaint.setColor(textColor);
  413. monthPaint.setAntiAlias(true);
  414. float textSize = cellHeight * 0.4f;
  415. Log.d(TAG, "text size:" + textSize);
  416. monthPaint.setTextSize(textSize);
  417. monthPaint.setTypeface(Typeface.DEFAULT_BOLD);
  418. weekPaint = new Paint();
  419. weekPaint.setColor(textColor);
  420. weekPaint.setAntiAlias(true);
  421. float weekTextSize = weekHeight * 0.6f;
  422. weekPaint.setTextSize(weekTextSize);
  423. weekPaint.setTypeface(Typeface.DEFAULT_BOLD);
  424. datePaint = new Paint();
  425. datePaint.setColor(textColor);
  426. datePaint.setAntiAlias(true);
  427. float cellTextSize = cellHeight * 0.5f;
  428. datePaint.setTextSize(cellTextSize);
  429. datePaint.setTypeface(Typeface.DEFAULT_BOLD);
  430. boxPath = new Path();
  431. // boxPath.addRect(0, 0, width, height, Direction.CW);
  432. // boxPath.moveTo(0, monthHeight);
  433. boxPath.rLineTo(width, 0);
  434. boxPath.moveTo(0, monthHeight + weekHeight);
  435. boxPath.rLineTo(width, 0);
  436. for (int i = 1; i < 6; i++) {
  437. boxPath.moveTo(0, monthHeight + weekHeight + i * cellHeight);
  438. boxPath.rLineTo(width, 0);
  439. boxPath.moveTo(i * cellWidth, monthHeight);
  440. boxPath.rLineTo(0, height - monthHeight);
  441. }
  442. boxPath.moveTo(6 * cellWidth, monthHeight);
  443. boxPath.rLineTo(0, height - monthHeight);
  444. // preMonthBtnPath = new Path();
  445. // int btnHeight = (int) (monthHeight * 0.6f);
  446. // preMonthBtnPath.moveTo(monthChangeWidth / 2f, monthHeight / 2f);
  447. // preMonthBtnPath.rLineTo(btnHeight / 2f, -btnHeight / 2f);
  448. // preMonthBtnPath.rLineTo(0, btnHeight);
  449. // preMonthBtnPath.close();
  450. // nextMonthBtnPath = new Path();
  451. // nextMonthBtnPath.moveTo(width - monthChangeWidth / 2f,
  452. // monthHeight / 2f);
  453. // nextMonthBtnPath.rLineTo(-btnHeight / 2f, -btnHeight / 2f);
  454. // nextMonthBtnPath.rLineTo(0, btnHeight);
  455. // nextMonthBtnPath.close();
  456. monthChangeBtnPaint = new Paint();
  457. monthChangeBtnPaint.setAntiAlias(true);
  458. monthChangeBtnPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  459. monthChangeBtnPaint.setColor(btnColor);
  460. cellBgPaint = new Paint();
  461. cellBgPaint.setAntiAlias(true);
  462. cellBgPaint.setStyle(Paint.Style.FILL);
  463. cellBgPaint.setColor(cellSelectedColor);
  464. }
  465. }
  466. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/930104
推荐阅读
相关标签
  

闽ICP备14008679号