Android android-times-square一款好用的日历控件
来源:互联网 发布:压缩的js还原 编辑:程序博客网 时间:2024/05/18 12:34
最近在项目中使用到了 android-times-square 日历控件,在网上搜了挺多博客结果都不是很满意,到 git 上看了源码。终于达到了自己想要的效果
以下是我使用的一些小细节,希望可以帮到第一次使用 android-times-square 的你。
1、先将 android-times-square 依赖到项目中去:
compile 'com.squareup:android-times-square:1.6.5@aar'
2、在布局中使用 CalendarPickerView :
3、使用
public class MainActivity extends AppCompatActivity { private CalendarPickerView pickerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pickerView= (CalendarPickerView) findViewById(R.id.calendar);//初始化日历控件 //将自定义的日期设置配置到日历中 SampleDecorator decorator=new SampleDecorator(this); List<CalendarCellDecorator> d=new ArrayList<>(); d.add(decorator); pickerView.setDecorators(d); //设置日历可显示的时间 add()第一个参数可选为 Week,Month,Year 第二个参数为第一个参数的数量 Calendar nextYear = Calendar.getInstance(); nextYear.add(Calendar.YEAR, 2); Date today = new Date(); //默认设置智能选择一个日期// pickerView.init(today, nextYear.getTime()).withSelectedDate(today); //如果想要选择多个日期,使用下面这行代码 通过inMode()可以选择三种形式的选择模式 pickerView.init(today, nextYear.getTime()).inMode(CalendarPickerView.SelectionMode.RANGE); }}
4、如果想要实现自定义日期的效果 需要自己定义一个类实现 CalendarCellDecorator 重写里面的方法来设置自己的日期背景 字体等效果
public class SampleDecorator implements CalendarCellDecorator { private Context context; public SampleDecorator(Context context) { this.context = context; } @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void decorate(CalendarCellView cellView, Date date) { if (cellView.isSelectable()) { //先通过是否可选方法来区分时间,如果可选则再判断是否已选 if (cellView.isSelected()) {//再通过是否已选来设置日期的背景图片 cellView.setBackground(context.getResources().getDrawable(R.mipmap.ic_launcher_round, null)); } else { cellView.setBackground(context.getResources().getDrawable(R.mipmap.time_13x, null)); } }else {//如果为不可选时间则直接设置日期背景 cellView.setBackground(context.getResources().getDrawable(R.mipmap.time_23x,null)); } }}这里我只是简单的配置了不同状态下的日期背景。
到这里你应该就可以简单的使用 android-times-square 了。
0 0
- Android android-times-square一款好用的日历控件
- 学习 square 日历框架 android-times-square
- android-times-square的使用
- android-times-square日期控件使用
- Android一款可定制的日历控件
- 开源框架android-times-square实现日历选择日期
- android-times-square日历开源库的导入,以及导入后出现的问题
- My97 DatePicker一款好用的日历控件
- 一款灵活好用的日历控件Kalendae
- Android-times-square自定义样式
- 一款好用的日历插件
- Android推荐一款很不错的刷新控件——既简单又好用
- 一款好看的日历控件
- Android 日历控件的实现
- android日历控件的使用
- 一款好用的banner轮播图控件
- 一个比较好用的日历控件
- 几个好用的日历控件
- 浅谈强化学习(一)
- Effective C++------读书笔记
- Instant Run导致的java.lang.ClassNotFoundException错误
- 淘宝npm镜像安装
- 客户每天经常询问一堆问题,怎么解决?
- Android android-times-square一款好用的日历控件
- Signing for requires a development team. Select a development team in the project editor. Code
- JDBC思考感悟(上)
- 51Nod-1217-Minimum Modular
- HTML <input> autocomplete
- Linux USB驱动框架分析
- unit7进程
- i春秋的戏说春秋writeup
- Android监听home键的方法