一個日歷ListView,一行顯示一個月:CalendarListview

jopen 10年前發布 | 44K 次閱讀 Android開發 移動開發 CalendarListview

這個項目在一個ListView中實現了一個日歷。一行顯示一個月,方便用戶選擇日期。

CalendarListview

CalendarListview

 

CalendarListview GIF

Integration

The lib is available on Maven Central, you can find it with Gradle, please

dependencies {
    compile 'com.github.traex:calendarlistview:library:1.1.1'
}

用法

Declare a DayPickerView inside your layout XML file:

  <com.andexert.calendarlistview.library.DayPickerView
         android:id="@+id/pickerView"
         xmlns:calendar="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
         android:layout_height="match_parent"/>

Next, you have to implement DatePickerController in your Activity or your Fragment. You will have to set getMaxYear and onDayOfMonthSelected. The first one is the max year between the current one and this maxYear. The second one is called every time user selects a new date.

    @Override
    public int getMaxYear()
    {
        return 2015;
    }

    @Override
    public void onDayOfMonthSelected(int year, int month, int day)
    {
        Log.e("Day Selected", day + " / " + month + " / " + year);
    }

定制

CalendarListview完全可定制:

  • app:colorCurrentDay [color def:#ff999999] --> The current day is always in bold but you can change its color
  • app:colorSelectedDayBackground [color def:#E75F49] --> If you click on a day, a circle indicator or a rouded rectangle indicator will be draw.
  • app:colorSelectedDayText [color def:#fff2f2f2] --> This is the text color of a selected day
  • app:colorPreviousDay [color def:#ff999999] --> In the current month you can choose to have a specific color for the past days
  • app:colorNormalDay [color def:#ff999999] --> Default text color for a day
  • app:colorMonthName [color def:#ff999999] --> Month name and year text color
  • app:colorDayName [color def:#ff999999] --> Day name text color
  • app:textSizeDay [dimension def:16sp] --> Font size for numeric day
  • app:textSizeMonth [dimension def:16sp] --> Font size for month name
  • app:textSizeDayName [dimension def:10sp] --> Font size for day name
  • app:headerMonthHeight [dimension def:50dip] --> Height of month name
  • app:drawRoundRect [boolean def:false] --> Draw a rounded rectangle for selected days instead of a circle
  • app:selectedDayRadius [dimension def:16dip] --> Set radius if you use default circle indicator
  • app:calendarHeight [dimension def:270dip] --> Height of each month/row
  • app:enablePreviousDay [boolean def:true] --> Enable past days in current month
  • app:startCurrentMonth [boolean def:false] --> Start listview at the current month
  • app:currentDaySelected [boolean def:false] --> Select current day by default

項目主頁:http://www.baiduhome.net/lib/view/home/1410771410976

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!