晚期代码癌患者android杂记安卓View学习

Android RecyclerView日期选择控件进化版

2016-12-21  本文已影响2487人  Galaxy北爱

在App应用开发中有很多时候我们都需要用到日期选择,比如出行日期,日期备忘录等,也有专门针对日历开发的App,今天这里就是一个基于RecyclerView实现的高效率日历控件。

device-2016-12-21-095818.png

1.创建一个activity_calendar.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:calendar="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:background="@color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <com.andexert.calendarlistview.library.DayPickerView
        android:id="@+id/day_picker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        calendar:colorSelectedDayBackground="@color/color_48c4fe"
        calendar:colorNormalDay="@android:color/black"
        calendar:colorMonthName="@android:color/black"
        calendar:colorDayName="@android:color/black"
        calendar:textSizeDay="14sp"
        calendar:textSizeMonth="14sp"
        calendar:textSizeDayName="14sp"
        calendar:currentDaySelected="false"
        calendar:colorPreviousDay="@android:color/darker_gray"
        calendar:enablePreviousDay="false"
        calendar:selectedDayRadius="18dp"
        calendar:showMonthDay="false"
        calendar:selectSingle="true"
        calendar:drawRoundRect="false"/>
</LinearLayout>
DayPickerView的属性说明:

2.代码使用部分

设置最小的可选日期
mDayPickerView.setMinDay(calendar);
设置最大日期需要实现接口DatePickerController,按照年计算,可选部分直到设置年份的今天
Paste_Image.png
单选逻辑实现方法
Paste_Image.png
多选逻辑实现
Paste_Image.png device-2016-12-21-091705.png
删除选择的日期
mDayPickerView.getSelectedDays().setFirst(null);
mDayPickerView.getSelectedDays().setLast(null);
//刷新日历
mDayPickerView.setUpAdapter();
calendar.gif

如果需要了解这个日历的前身,请点击我,说了这么多,没有源码就是耍流氓
源码传送门
日历后期将会根据研究持续更新,如果你喜欢,那就一起来研究吧,后期我将会给大家带来更多实用,可靠并且拓展性强大的控件。

上一篇下一篇

猜你喜欢

热点阅读