项目作者: laserwave

项目描述 :
an android widget to show calendar
高级语言: Java
项目地址: git://github.com/laserwave/calendar_view.git
创建时间: 2016-05-21T11:39:44Z
项目社区:https://github.com/laserwave/calendar_view

开源协议:

下载


Android-CalendarView

normal mode

record mode

Support API LEVEL >= 7.

Including In Your Project

Gradle

Add the following code in the build.gradle of your module.

  1. dependencies {
  2. compile 'cn.zhikaizhang.calendar:library:1.0.1'
  3. }

Download the source code

You can also download the source code of the project and import the library module into your project as a module so that you can modify the source code.

Usage

For a working implementation of this project see the sample/ folder.

Step1. Include one of the widgets in your xml. You can set the mode 0 for the normal mode and 1 for the record mode. You can also specify the mode in your java code.

  1. <cn.zhikaizhang.calendarview.CalendarView
  2. android:id="@+id/calendarView"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. app:mode="0">
  6. </cn.zhikaizhang.calendarview.CalendarView>

Step2. Refresh the CalendarView. You will use refresh0() for the normal calendar mode and refresh1() for the record mode.

  1. calendarView.setMode(0);
  2. //refresh the CalendarView with new values of year and month
  3. calendarView.refresh0(year, month);
  4. calendarView.setMode(1);
  5. //simulate to get data
  6. int days = calendarView.daysOfCurrentMonth();
  7. boolean data[] = new boolean[days+1];
  8. int today = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
  9. for(int i = 1; i <= days; i++){
  10. if(i <= today){
  11. data[i] = (Math.random() > 0.5);
  12. }else{
  13. data[i] = false;
  14. }
  15. }
  16. calendarView.refresh1(data);

Step3. Set the appearance you like. You can set the language to English or Chinese. You can also modify the color and size of the text.

  1. /**
  2. * modify the language of head of the calendar
  3. * legal values of style : 0 - 3
  4. * 0, 1, 2 : Chinese, 3 : English
  5. */
  6. calendarView.setWeekTextStyle(style);
  7. //set the text color of the head
  8. calendarView.setWeekTextColor(Color.BLACK);
  9. /**
  10. * set the scale of text size of the head
  11. * legal values : 0.0f - 1.0f
  12. */
  13. calendarView.setWeekTextSizeScale(0.5f);
  14. //set the text color of the calendar cell
  15. calendarView.setCalendarTextColor(Color.BLACK);
  16. /**
  17. * set the scale of text size of the calendar cell
  18. * legal values : 0.0f - 1.0f
  19. */
  20. calendarView.setTextSizeScale(0.5f);
  21. /**
  22. * set the color of the text of selected day
  23. */
  24. calendarView.setSelectedDayTextColor(Color.WHITE);
  25. /**
  26. * set the color of the background of selected day
  27. */
  28. calendarView.setSelectedDayBgColor(Color.rgb(124, 180, 246));
  29. /**
  30. * set the color of the background of today
  31. */
  32. calendarView.setTodayBgColor(Color.rgb(124, 180, 246));

Step4. Implement the callback. Set the OnRefreshListener to do what you want after you refresh the calendar and set the OnItemClickListener to do what you want after you click a day.

  1. calendarView.setOnRefreshListener(new ICalendarView.OnRefreshListener() {
  2. @Override
  3. public void onRefresh() {
  4. yearMonthTextView.setText(getYearMonthText(calendarView.getYear(), calendarView.getMonth()));
  5. }
  6. });
  7. calendarView.setOnItemClickListener(new ICalendarView.OnItemClickListener() {
  8. @Override
  9. public void onItemClick(int day) {
  10. int year = calendarView.getYear();
  11. int month = calendarView.getMonth();
  12. Toast.makeText(Demo0.this, year + "-" + month + "-" + day, Toast.LENGTH_SHORT).show();
  13. }
  14. });

Author

License

  1. Copyright 2016 ZhikaiZhang
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.