├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── hdl │ │ └── com │ │ └── calendardemo │ │ ├── BlankFragment.java │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ └── fragment_blank.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── calendarview_lib ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── hdl │ │ └── calendardialog │ │ ├── CalendarView.java │ │ ├── CalendarViewDialog.java │ │ └── DateUtils.java │ └── res │ ├── drawable │ ├── circle.xml │ ├── circle_ring.xml │ ├── empty_divider.xml │ ├── ic_arrow_left.xml │ ├── ic_arrow_right.xml │ ├── ring.xml │ ├── shape_bg.xml │ └── shape_dialog.xml │ ├── layout │ ├── calendar_day_of_the_month_layout.xml │ ├── calendar_month_layout.xml │ ├── calendar_picker_layout.xml │ ├── calendar_week_layout.xml │ └── dialog_calendar.xml │ ├── mipmap-xxhdpi │ ├── ic_last_month.png │ └── ic_next_month.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ └── styles.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── image.png ├── image1.png └── image2.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DatepickerDialog [![](https://jitpack.io/v/huangdali/DatepickerDialog.svg)](https://jitpack.io/#huangdali/DatepickerDialog) 2 | 3 | 日期选择器,日历选择器,可标记某一天,DatepickerDialog,Tagged calendar 4 | 5 | - 单选某一天 6 | - 标记某一天 7 | - 今天之后不可点击(灰色) 8 | - 选择回调(未标记回调) 9 | - 自动记录上一次的选择 10 | - 可限制只显示两个月(默认不限制) 11 | - 设置默认选中选中某一天 12 | 13 | ## How to 14 | 15 | To get a Git project into your build: 16 | 17 | ### Step 1. Add the JitPack repository to your build file 18 | 19 | Add it in your root build.gradle at the end of repositories: 20 | 21 | allprojects { 22 | repositories { 23 | ... 24 | maven { url 'https://jitpack.io' } 25 | } 26 | } 27 | ### Step 2. Add the dependency 28 | 29 | dependencies { 30 | compile 'com.github.huangdali:DatepickerDialog:v1.0.7' 31 | } 32 | 33 | ### 效果图: 34 | 35 | ### 初始状态 36 | ![](https://github.com/huangdali/DatepickerDialog/blob/master/images/image.png) 37 | 38 | ### 选中状态 39 | ![](https://github.com/huangdali/DatepickerDialog/blob/master/images/image1.png) 40 | 41 | ### 切换月份 42 | ![](https://github.com/huangdali/DatepickerDialog/blob/master/images/image2.png) 43 | 44 | ### DMEO 45 | ```java 46 | CalendarViewDialog.getInstance() 47 | .init(this) 48 | .addMarks(markDays) 49 | .setLimitMonth(true) 50 | .show(new CalendarView.OnCalendarClickListener() { 51 | @Override 52 | public void onDayClick(Calendar daySelectedCalendar) { 53 | CalendarViewDialog.getInstance().close(); 54 | Toast.makeText(MainActivity.this, "选择的天数 : " + DateUtils.getDateTime(daySelectedCalendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); 55 | } 56 | 57 | @Override 58 | public void onDayNotMarkClick(Calendar daySelectedCalendar) { 59 | Toast.makeText(MainActivity.this, "当前时间无回放(没有标记)", Toast.LENGTH_SHORT).show(); 60 | } 61 | }); 62 | ``` 63 | 64 | ### 【标记某一天】markDays格式 65 | ```java 66 | private List markDays = new ArrayList<>(); 67 | ``` 68 | 69 | 70 | 模拟数据: 71 | 72 | ```java 73 | for (int i = 0; i < 5; i++) { 74 | markDays.add(System.currentTimeMillis() - i * 24 * 60 * 60 * 1000); 75 | } 76 | ``` 77 | 78 | ### 更新日志 79 | 80 | v1.0.7 ([2018.04.02]()) 81 | 82 | - 【新增】设置默认选中某一天 83 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.2" 6 | defaultConfig { 7 | applicationId "hdl.com.calendardemo" 8 | minSdkVersion 16 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | buildToolsVersion '26.0.2' 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 26 | compile project(':calendarview_lib') 27 | // compile 'com.github.huangdali:DatepickerDialog:v1.0.4' 28 | compile 'com.android.support:appcompat-v7:25.3.1' 29 | compile 'com.android.support:support-v4:25.3.1' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/hdl/com/calendardemo/BlankFragment.java: -------------------------------------------------------------------------------- 1 | package hdl.com.calendardemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.hdl.calendardialog.CalendarView; 10 | import com.hdl.calendardialog.CalendarViewDialog; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Calendar; 14 | import java.util.List; 15 | 16 | public class BlankFragment extends Fragment { 17 | private List markDays = new ArrayList<>(); 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | for (int i = 0; i < 5; i++) { 22 | markDays.add(System.currentTimeMillis() - i * 24 * 60 * 60 * 1000); 23 | } 24 | markDays.add(System.currentTimeMillis() - 12 * 24 * 60 * 60 * 1000); 25 | } 26 | 27 | @Override 28 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 29 | Bundle savedInstanceState) { 30 | // Inflate the layout for this fragment 31 | return inflater.inflate(R.layout.fragment_blank, container, false); 32 | } 33 | public void onDateChoise(View view){ 34 | CalendarViewDialog.getInstance() 35 | .init(getActivity()) 36 | .addMarks(markDays) 37 | .setLimitMonth(true) 38 | .show(new CalendarView.OnCalendarClickListener() { 39 | @Override 40 | public void onDayClick(Calendar daySelectedCalendar) { 41 | CalendarViewDialog.getInstance().close(); 42 | } 43 | 44 | @Override 45 | public void onDayNotMarkClick(Calendar daySelectedCalendar) { 46 | } 47 | }); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/hdl/com/calendardemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package hdl.com.calendardemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.FragmentActivity; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentTransaction; 7 | import android.view.View; 8 | import android.widget.Toast; 9 | 10 | import com.hdl.calendardialog.CalendarView; 11 | import com.hdl.calendardialog.CalendarViewDialog; 12 | import com.hdl.calendardialog.DateUtils; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Calendar; 16 | import java.util.List; 17 | 18 | public class MainActivity extends FragmentActivity { 19 | private List markDays = new ArrayList<>(); 20 | // private RobotoCalendarView robotoCalendarView; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | //默认显示本地回放 27 | FragmentManager manager = getSupportFragmentManager(); 28 | FragmentTransaction transaction = manager.beginTransaction(); 29 | transaction.replace(R.id.fl_parent, new BlankFragment()).commit(); 30 | currentTime=System.currentTimeMillis(); 31 | // // Gets the calendar from the view 32 | // robotoCalendarView = (RobotoCalendarView) findViewById(R.id.robotoCalendarPicker); 33 | // 34 | // // Set listener, in this case, the same activity 35 | // robotoCalendarView.show(this); 36 | // 37 | // robotoCalendarView.setShortWeekDays(true); 38 | // 39 | // robotoCalendarView.showDateTitle(true); 40 | // 41 | // robotoCalendarView.updateView(); 42 | for (int i = 0; i < 5; i++) { 43 | markDays.add(System.currentTimeMillis() - i * 24 * 60 * 60 * 1000); 44 | } 45 | markDays.add(System.currentTimeMillis() - 12 * 24 * 60 * 60 * 1000); 46 | // robotoCalendarView.addMarkDays(markDays); 47 | } 48 | 49 | 50 | public void onDateChoise(View view) { 51 | CalendarViewDialog.getInstance() 52 | .init(this) 53 | .addMarks(markDays) 54 | .setLimitMonth(true) 55 | .show(new CalendarView.OnCalendarClickListener() { 56 | @Override 57 | public void onDayClick(Calendar daySelectedCalendar) { 58 | CalendarViewDialog.getInstance().close(); 59 | Toast.makeText(MainActivity.this, "选择的天数 : " + DateUtils.getDateTime(daySelectedCalendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); 60 | } 61 | 62 | @Override 63 | public void onDayNotMarkClick(Calendar daySelectedCalendar) { 64 | Toast.makeText(MainActivity.this, "当前时间无回放(没有标记)", Toast.LENGTH_SHORT).show(); 65 | } 66 | }); 67 | 68 | } 69 | private long currentTime; 70 | public void onSelectedDay(View view) { 71 | currentTime+=24 * 60 * 60 * 1000; 72 | CalendarViewDialog.getInstance() 73 | .init(this) 74 | .setSelectedDay(currentTime); 75 | } 76 | 77 | public void onSelectedDaySub(View view) { 78 | currentTime-=24 * 60 * 60 * 1000; 79 | CalendarViewDialog.getInstance() 80 | .init(this) 81 | .setSelectedDay(currentTime); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |