獨立的Android小部件,用於從日曆視圖中選擇一個日期。
在您的佈局XML中包含CalendarPickerView
。
< com .squareup.timessquare.CalendarPickerView
android : id = " @+id/calendar_view "
android : layout_width = " match_parent "
android : layout_height = " match_parent "
/>
這是一個相當大的控制,因此明智的做法是在您的佈局中提供足夠的空間。在小型設備上,建議使用對話框,全屏片段或專用活動。在平板電腦等較大的設備上,不建議顯示全屏。佔用佈局或對話框部分的片段是一個更好的選擇。
在您的活動/對話框或片段的onCreateView
onCreate
中,使用一系列有效日期以及當前選擇的日期初始化視圖。
Calendar nextYear = Calendar . getInstance ();
nextYear . add ( Calendar . YEAR , 1 );
CalendarPickerView calendar = ( CalendarPickerView ) findViewById ( R . id . calendar_view );
Date today = new Date ();
calendar . init ( today , nextYear . getTime ())
. withSelectedDate ( today );
視圖的默認模式是具有一個可選的日期。如果您希望用戶能夠選擇多個日期或日期範圍,請使用InMode()方法:
calendar . init ( today , nextYear . getTime ())
. inMode ( RANGE );
最新版本可以在zip中下載,並由您的應用程序引用為庫項目。
您也可以通過Maven依靠圖書館:
< dependency >
< groupId >com.squareup</ groupId >
< artifactId >android-times-square</ artifactId >
< version >1.6.5</ version >
< type >apklib</ type >
</ dependency >
或gradle:
compile ' com.squareup:android-times-square:1.6.5@aar '
開發版本的快照可在Sonatype的snapshots
存儲庫中獲得。
Copyright 2012 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.