项目地址:http://download.csdn.net/download/weixin_40391500/10264219
private CalendarPickerView calendar;
private String date;
private Calendar nextYear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
nextYear = Calendar.getInstance();
date = DateChang.getNowTime("yyy-MM-dd");//获取当天日期
nextYear.add(Calendar.MONTH, 3);//设置显示可选择几个月
calendar.init(new Date(), nextYear.getTime())
.inMode(CalendarPickerView.SelectionMode.SINGLE) //
.withSelectedDate(DateChang.strToDate(date));
calendar.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() {
@Override
public void onDateSelected(Date date) {
String selectDate = DateChang.getDate(date).substring(0, 11);
Log.e("-------", selectDate);
}
});
}
<com.example.calendardemo.timessquare.CalendarPickerView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:scrollbarStyle="outsideOverlay" />