android-times-square的使用
来源:互联网 发布:sql alter column 编辑:程序博客网 时间:2024/05/04 15:45
本文简单介绍了Square出品的android-times-square的使用。
一,在gradle里添加依赖
compile 'com.squareup:android-times-square:1.6.5@aar'二,布局文件如下
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="liubo.is.handsome.activity.MainActivity"> <TextView android:id="@+id/calendar_tip" android:layout_width="match_parent" android:layout_height="@dimen/textview_height" android:gravity="center" /> <com.squareup.timessquare.CalendarPickerView android:id="@+id/calendarView" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none"/></LinearLayout>三,activity中代码如下
package liubo.is.handsome.activity;import android.os.Bundle;import android.widget.TextView;import com.squareup.timessquare.CalendarPickerView;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import liubo.is.handsome.R;import liubo.is.handsome.base.BaseActivity;import liubo.is.handsome.utils.LogUtils;/** * Created by liubo on 2017/2/6. * Description: * */public class CalendarActivity extends BaseActivity { TextView calendarTip; CalendarPickerView calendar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calendar); initView(); } private void initView() { calendarTip = (TextView) findViewById(R.id.calendar_tip); calendar = (CalendarPickerView) findViewById(R.id.calendarView); calendar.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() { @Override public void onDateSelected(final Date date) { LogUtils.lb("onDateSelected = " + formatDate(date)); final int size = calendar.getSelectedDates().size(); if (size % 2 == 0) { calendarTip.setText(calendarTip.getText() + " - " + formatDate(date) + " -- > " + size + " 天"); } else { calendarTip.setText("" + formatDate(date)); } } @Override public void onDateUnselected(Date date) {// LogUtils.lb("onDateUnselected = " + date); } }); Calendar nextYear = Calendar.getInstance(); nextYear.add(Calendar.YEAR, 1); Date today = new Date(); calendar.init(today, nextYear.getTime()).withSelectedDate(today); //默认是只选择一个日期,如果想要选择多个日期,使用下面这行代码 calendar.init(today, nextYear.getTime()).inMode(CalendarPickerView.SelectionMode.RANGE); } private String formatDate(Date date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String str = format.format(date); return str; }}四,效果图如下
------------------------------------------------------华丽丽的分割线----------------------------------------------------------------------------------------------------
五,附注
上面的例子使用的CalendarPickerView.SelectionMode.RANGE,有兴趣的可以尝试另外两种方式。日期选择模式是个枚举类
public enum SelectionMode { /** * Only one date will be selectable. If there is already a selected date and you select a new * one, the old date will be unselected. */ SINGLE, /** Multiple dates will be selectable. Selecting an already-selected date will un-select it. */ MULTIPLE, /** * Allows you to select a date range. Previous selections are cleared when you either: * <ul> * <li>Have a range selected and select another date (even if it's in the current range).</li> * <li>Have one date selected and then select an earlier date.</li> * </ul> */ RANGE }
===================================================================================================================
0 0
- android-times-square的使用
- android-times-square日期控件使用
- Android-times-square自定义样式
- Android android-times-square一款好用的日历控件
- 学习 square 日历框架 android-times-square
- android-times-square日历开源库的导入,以及导入后出现的问题
- 开源框架android-times-square实现日历选择日期
- clock,clock_t,times的注意事项
- times系统调用的例子
- Activity life times——Android
- Square 开源 Android
- Times附近有语法错误的解决方案
- Times New Roman字体的历史
- Georgia与Times字体的比较
- Times New Roman字体的历史
- 获得某个电话的通话记录次数times
- 7.5.1 Point-in-Time Recovery Using Event Times 使用Event Times 基于时间点恢复
- Square 之 Retrofit 使用详解
- javascript笔记--(第二十四章)事件
- 抽象类
- 进制之间的转换(整数)
- Java新手入门规范化的注意点
- Glide里的一些坑
- android-times-square的使用
- LintCode 423:Valid Parentheses
- Nginx+Tomcat搭建高性能负载均衡集群
- 基础练习 十六进制转十进制
- C++函数指针和指针函数
- Java IO流学习总结
- myeclipse根据数据库中表反向生成JavaBean的方法
- I2C子系统
- 法律法规与标准规范 考纲与考试要点