AndroidPicker: 安卓选择器类库,包括日期时间选择器、单项选择器、地址选择器、颜色选择器、文件目录选择器、数字选择器、星座选择器等

jopen 9年前

安卓选择器类库,包括日期选择器、时间选择器、单项选择器、城市选择器、颜色选择器、文件选择器、目录选择器、数字选择器、星座选择器、生肖选择器等。 欢迎大伙儿在issues提交你的意见或建议

项目分支说明:
Branch_OldAndroidPicker-基于android-wheel的旧版选择器,不再维护;
release_0.9-WheelPicker、ColorPicker、FilePicker是分开的三个模块;
master-默认的最新分支,release_0.9之后支持maven库依赖。

Install

“app”是测试用例;“library”包括WheelPicker、ColorPicker、FilePicker,
WheelPicker包括DatePicker、TimePicker、OptionPicker、AddressPicker、NumberPicker等,
如果需要所有的的选择器的话,建议依赖“AndroidPicker”。

dependencies {      compile 'cn.qqtheme.framework:AndroidPicker:latest.integration'      //compile 'cn.qqtheme.framework:WheelPicker:latest.integration'      //compile 'cn.qqtheme.framework:ColorPicker:latest.integration'      //compile 'cn.qqtheme.framework:FilePicker:latest.integration'  }

也可以手动下载本项目,复制“library”命名为“AndroidPicker”,然后:

dependencies {      compile project('AndroidPicker')  }

窗口进入退出动画(可选,默认动画为淡入淡出)

<resources>      <style name="Animation.CustomPopup" parent="@android:style/Animation">          <item name="android:windowEnterAnimation">@anim/popup_in</item>          <item name="android:windowExitAnimation">@anim/popup_out</item>      </style>  </resources>
picker.setAnimationStyle(R.style.Animation_CustomPopup);

Sample

日期选择器:

DatePicker picker = new DatePicker(this);          picker.setRange(1990, 2015);//年份范围          picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {              @Override              public void onDatePicked(String year, String month, String day) {                  showToast(year + "-" + month + "-" + day);              }          });          picker.show();

时间选择器:

//默认选中当前时间          TimePicker picker = new TimePicker(this);          picker.setTopLineVisible(false);          picker.setOnTimePickListener(new TimePicker.OnTimePickListener() {              @Override              public void onTimePicked(String hour, String minute) {                  showToast(hour + ":" + minute);              }          });          picker.show();

单项选择器(可用于性别、学历、职业、星座等选择):

OptionPicker picker = new OptionPicker(this, new String[]{                  "第一项", "第二项", "这是一个很长很长很长很长很长很长很长很长很长的很长很长的很长很长的项"          });          picker.setOffset(2);          picker.setSelectedIndex(1);          picker.setTextSize(11);          picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {              @Override              public void onOptionPicked(String option) {                  showToast(option);              }          });          picker.show();

数字选择器(可用于身高、体重、年龄等选择):

NumberPicker picker = new NumberPicker(this);          picker.setOffset(2);//偏移量          picker.setRange(145, 200);//数字范围          picker.setSelectedItem(172);          picker.setLabel("厘米");          picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {              @Override              public void onOptionPicked(String option) {                  showToast(option);              }          });          picker.show();

地址选择器(含省级、地级、县级):

ArrayList<AddressPicker.Province> data = new ArrayList<AddressPicker.Province>();          String json = AssetsUtils.readText(this, "city.json");          data.addAll(JSON.parseArray(json, AddressPicker.Province.class));          AddressPicker picker = new AddressPicker(this, result);          picker.setSelectedItem("贵州", "贵阳", "花溪");          picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() {              @Override              public void onAddressPicked(String province, String city, String county) {                  showToast(province + city + county);              }          });          picker.show();

地址选择器(含地级、县级):

ArrayList<AddressPicker.Province> data = new ArrayList<AddressPicker.Province>();              String json = AssetsUtils.readText(this, "city2.json");              data.addAll(JSON.parseArray(json, AddressPicker.Province.class));              AddressPicker picker = new AddressPicker(this, data);              picker.setHideProvince(true);              picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() {                  @Override                  public void onAddressPicked(String province, String city, String county) {                      showToast(province + city + county);                  }              });              picker.show();

星座选择器:

ConstellationPicker picker = new ConstellationPicker(this);          picker.setTopBackgroundColor(0xFFEEEEEE);          picker.setTopLineVisible(false);          picker.setCancelTextColor(0xFF33B5E5);          picker.setSubmitTextColor(0xFF33B5E5);          picker.setTextColor(0xFFFF0000, 0xFFCCCCCC);          picker.setLineColor(0xFFEE0000);          picker.setSelectedItem("射手");          picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {              @Override              public void onOptionPicked(String option) {                  showToast(option);              }          });          picker.show();

生肖选择器:

ChineseZodiacPicker picker = new ChineseZodiacPicker(this);          picker.setLineVisible(false);          picker.setSelectedItem("羊");          picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {              @Override              public void onOptionPicked(String option) {                  showToast(option);              }          });          picker.show();

颜色选择器:

ColorPicker picker = new ColorPicker(this);          picker.setInitColor(0xFFDD00DD);          picker.setOnColorPickListener(new ColorPicker.OnColorPickListener() {              @Override              public void onColorPicked(int pickedColor) {                  showToast(ConvertUtils.toColorString(pickedColor));              }          });          picker.show();

文件选择器(需要权限android.permission.READ_EXTERNAL_STORAGE):

FilePicker picker = new FilePicker(this);          picker.setShowHideDir(false);          picker.setRootPath(StorageUtils.getRootPath(this) + "Download/");          //picker.setAllowExtensions(new String[]{".apk"});          picker.setMode(FilePicker.Mode.File);          picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {              @Override              public void onFilePicked(String currentPath) {                  showToast(currentPath);              }          });          picker.show();

目录选择器(需要权限android.permission.READ_EXTERNAL_STORAGE):

FilePicker picker = new FilePicker(this);          picker.setMode(FilePicker.Mode.Directory);          picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {              @Override              public void onFilePicked(String currentPath) {                  showToast(currentPath);              }          });          picker.show();

Thanks

库项目修改了使用以下项目:
https://github.com/wangjiegulu/WheelView
https://github.com/jbruchanov/AndroidColorPicker
示例项目直接使用了以下项目:
https://github.com/alibaba/fastjson

Screenshots

日期选择器效果图
时间选择器效果图
单项选择器效果图
地址选择器效果图
地址选择器效果图
数字选择器效果图
星座选择器效果图
生肖选择器效果图
颜色选择器效果图
文件选择器效果图
目录选择器效果图

</h1> 项目地址: https://github.com/gzu-liyujiang/AndroidPicker