-
-
Notifications
You must be signed in to change notification settings - Fork 842
Picker
xuexiangjys edited this page Jan 12, 2019
·
6 revisions
选择器是Android中常用的控件,常用于时间、图片、地址等信息的选择。
时间选择器,支持自定义时间单位的选择。
- 演示效果
- 使用案例
mDatePicker = new TimePickerBuilder(getContext(), new OnTimeSelectListener() {
@Override
public void onTimeSelected(Date date, View v) {
ToastUtils.toast(DateUtils.date2String(date, DateUtils.yyyyMMdd.get()));
}
})
.setTimeSelectChangeListener(new OnTimeSelectChangeListener() {
@Override
public void onTimeSelectChanged(Date date) {
Log.i("pvTime", "onTimeSelectChanged");
}
})
.setTitleText("日期选择")
.build();
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtils.string2Date("2013-07-08 12:32:46", DateUtils.yyyyMMddHHmmss.get()));
mTimePicker = new TimePickerBuilder(getContext(), new OnTimeSelectListener() {
@Override
public void onTimeSelected(Date date, View v) {
ToastUtils.toast(DateUtils.date2String(date, DateUtils.yyyyMMddHHmmss.get()));
}
})
.setTimeSelectChangeListener(new OnTimeSelectChangeListener() {
@Override
public void onTimeSelectChanged(Date date) {
Log.i("pvTime", "onTimeSelectChanged");
}
})
.setType(TimePickerType.ALL)
.setTitleText("时间选择")
.isDialog(true)
.setOutSideCancelable(false)
.setDate(calendar)
.build();
条件选择器,支持自定义条件选择。
- 演示效果
- 使用案例
OptionsPickerView pvOptions = new OptionsPickerBuilder(getContext(), new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
//返回的分别是三个级别的选中位置
String tx = options1Items.get(options1).getPickerViewText() + "-" +
options2Items.get(options1).get(options2) + "-" +
options3Items.get(options1).get(options2).get(options3);
ToastUtils.toast(tx);
}
})
.setTitleText("城市选择")
.setDividerColor(Color.BLACK)
.setTextColorCenter(Color.BLACK) //设置选中项文字颜色
.setContentTextSize(20)
.isDialog(isDialog)
.setSelectOptions(defaultSelectOptions[0], defaultSelectOptions[1], defaultSelectOptions[2])
.build();
pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
pvOptions.show();
图片选择器,使用的是第三方的库PhotoPicker,支持单图片和多图片选择。
- 演示效果
- 使用案例
//单图片选择
PhotoPicker.builder()
.setPhotoCount(1)
.start(getContext(), this);
//多图片选择
PhotoPicker.builder()
.setPhotoCount(9)
.setGridColumnCount(4)
.start(getContext(), this);
//支持选择gif
PhotoPicker.builder()
.setShowCamera(true)
.setShowGif(true)
.start(getContext(), this);
- 注意需要增加如下依赖
implementation 'com.github.xuexiangjys:PhotoPicker:1.0.1'