项目地址:https://github.com/gzu-liyujiang/AndroidPicker
历史版本:https://github.com/gzu-liyujiang/AndroidPicker/blob/master/ChangeLog.md
依赖配置
// JitPack 远程仓库:https://jitpack.iomaven { 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() {@Overridepublic 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() {@Overridepublic 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();
DatimePicker
DatimePicker picker = new DatimePicker(this);
final DatimeWheelLayout wheelLayout = picker.getWheelLayout();
picker.setOnDatimePickedListener(new OnDatimePickedListener() {
@Override
public void onDatimePicked(int year, int month, int day, int hour, int minute, int second) {
String text = month + "月" + day + "日" + hour + ":" + minute;
// year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
// text += wheelLayout.getTimeWheelLayout().isAnteMeridiem() ? " 上午" : " 下午";//回调12小时制时显示上午还是下午
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}
});
wheelLayout.setDateMode(DateMode.MONTH_DAY);//设置年月日格式
wheelLayout.setTimeMode(TimeMode.HOUR_24_NO_SECOND);//设置小时分钟秒格式
wheelLayout.setRange(DatimeEntity.now(), DatimeEntity.dayOnFuture(1));//设置未来时间上线
wheelLayout.setDateLabel("年", "月", "日");//设置年月日文字内容
wheelLayout.setTimeLabel("时", "分", "秒");//设置小时分钟秒文字内容
picker.setTitle("设置您要预约的时间");
picker.show();