项目地址:https://github.com/gzu-liyujiang/AndroidPicker
历史版本:https://github.com/gzu-liyujiang/AndroidPicker/blob/master/ChangeLog.md
依赖配置
// JitPack 远程仓库:https://jitpack.io maven { url 'https://jitpack.io' }
所有选择器的基础窗体(用于自定义弹窗):
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:Common:<version>' }
滚轮选择器的滚轮控件(用于自定义滚轮选择器):
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:WheelView:<version>' }
单项/数字、二三级联动、日期/时间等滚轮选择器:
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:WheelPicker:<version>' }
省市区地址选择器:
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:AddressPicker:<version>' }
文件/目录选择器:
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:FilePicker:<version>' }
颜色选择器:
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:ColorPicker:<version>' }
日历日期选择器(README.md):
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:CalendarPicker:<version>' }
图片选择器(README.md):
dependencies { implementation 'com.github.gzu-liyujiang.AndroidPicker:ImagePicker:<version>' }
<version>对应这历史版本号,如下图:
implementation 'com.github.gzu-liyujiang.AndroidPicker:WheelView:4.1.12' implementation 'com.github.gzu-liyujiang.AndroidPicker:WheelPicker:4.1.12'
时间选择器
24小时
TimePicker picker = new TimePicker(this); TimeWheelLayout wheelLayout = picker.getWheelLayout(); wheelLayout.setTimeMode(TimeMode.HOUR_24_HAS_SECOND); wheelLayout.setTimeFormatter(new UnitTimeFormatter()); wheelLayout.setDefaultValue(TimeEntity.now()); wheelLayout.setResetWhenLinkage(false); picker.setOnTimePickedListener(new OnTimePickedListener() { @Override public void onTimePicked(int hour, int minute, int second) { ToastUtils.show(hour+" "+minute+" "+second); } }); picker.show();
12小时
TimePicker picker = new TimePicker(this); picker.setBodyWidth(140); TimeWheelLayout wheelLayout = picker.getWheelLayout(); wheelLayout.setRange(TimeEntity.target(0, 0, 0), TimeEntity.target(24, 59, 59)); wheelLayout.setTimeMode(TimeMode.HOUR_12_NO_SECOND); wheelLayout.setTimeLabel(":", " ", ""); wheelLayout.setDefaultValue(TimeEntity.target(24, 0, 0)); wheelLayout.setTimeStep(1, 10, 1); picker.setOnTimeMeridiemPickedListener(new OnTimeMeridiemPickedListener() { @Override public void onTimePicked(int hour, int minute, int second, boolean isAnteMeridiem) { String text = hour + ":" + minute + ":" + second; text += isAnteMeridiem ? " 上午" : " 下午"; Toast.makeText(getApplication(), text, Toast.LENGTH_SHORT).show(); } }); picker.show();