独立的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.