• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Java
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple PickerView for Android - code from https://github.com/saiwu-bigkoo/Android-PickerView

Android-PickerView-Library

这是一个高仿 IOS PickerView 控件的库:https://github.com/Airsaid/Android-PickerView-Library。在 https://github.com/saiwu-bigkoo/Android-PickerView 代码基础上进行封装、优化。由于原库作者不再维护,所以新开了该库。后期如有时间,将会对整体代码重构,核心采用自定义 LayouManager 实现。

原库已经有人接手更新,并且代码已经重构。推荐大家使用,地址:https://github.com/saiwu-bigkoo/Android-PickerView

该库暂时停止维护,后续可能会进行重构(重构前建议大家不要使用)

预览

使用

  • 首先需要在 build.gradle 文件中添加依赖:
dependencies {
   compile 'com.airsaid.library:pickerview:1.0.3'
}

添加好依赖后,重新同步工程。可根据需求使用如下选择器:

  • 城市选择:
        CityPickerView mCityPickerView = new CityPickerView(this);
        // 设置点击外部是否消失
//        mCityPickerView.setCancelable(true);
        // 设置滚轮字体大小
//        mCityPickerView.setTextSize(18f);
        // 设置标题
//        mCityPickerView.setTitle("我是标题");
        // 设置取消文字
//        mCityPickerView.setCancelText("我是取消文字");
        // 设置取消文字颜色
//        mCityPickerView.setCancelTextColor(Color.GRAY);
        // 设置取消文字大小
//        mCityPickerView.setCancelTextSize(14f);
        // 设置确定文字
//        mCityPickerView.setSubmitText("我是确定文字");
        // 设置确定文字颜色
//        mCityPickerView.setSubmitTextColor(Color.BLACK);
        // 设置确定文字大小
//        mCityPickerView.setSubmitTextSize(14f);
        // 设置头部背景
//        mCityPickerView.setHeadBackgroundColor(Color.RED);
        mCityPickerView.setOnCitySelectListener(new OnSimpleCitySelectListener(){
                    @Override
                    public void onCitySelect(String prov, String city, String area) {
                        // 省、市、区 分开获取
                        Log.e(TAG, "省: " + prov + " 市: " + city + " 区: " + area);
                    }

                    @Override
                    public void onCitySelect(String str) {
                        // 一起获取
                        Toast.makeText(MainActivity.this, "选择了:" + str, Toast.LENGTH_SHORT).show();
                    }
        });
        mCityPickerView.show();
  • 时间选择:
 //     TimePickerView 同样有上面设置样式的方法
        TimePickerView mTimePickerView = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        // 设置是否循环
//        mTimePickerView.setCyclic(true);
        // 设置滚轮文字大小
//        mTimePickerView.setTextSize(TimePickerView.TextSize.SMALL);
        // 设置时间可选范围(结合 setTime 方法使用,必须在)
//        Calendar calendar = Calendar.getInstance();
//        mTimePickerView.setRange(calendar.get(Calendar.YEAR) - 100, calendar.get(Calendar.YEAR));
        // 设置选中时间
//        mTimePickerView.setTime(new Date());
        mTimePickerView.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date) {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
                Toast.makeText(MainActivity.this, format.format(date), Toast.LENGTH_SHORT).show();
            }
        });
        mTimePickerView.show();
  • 选项选择:
        OptionsPickerView<String> mOptionsPickerView = new OptionsPickerView<>(this);
        final ArrayList<String> list = new ArrayList<>();
        list.add("男");
        list.add("女");
        // 设置数据
        mOptionsPickerView.setPicker(list);
        // 设置选项单位
//        mOptionsPickerView.setLabels("性");
        mOptionsPickerView.setOnOptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int option1, int option2, int option3) {
                String sex = list.get(option1);
                Toast.makeText(MainActivity.this, sex, Toast.LENGTH_SHORT).show();
            }
        });
        mOptionsPickerView.show();

更新日志

  • 1.0.2:修复部分城市文字乱码bug,修复设置字体过小后分割线无法对齐bug。
  • 1.0.1:修复内存泄露问题,修复设置setTime()方法后字体设置无效bug。

联系我

感谢

More Repositories

1

AndroidLocalizePlugin

🌏 Android localization plugin. supports multiple languages and multiple translators.
Java
507
star
2

AccountBook

[停止维护] 一个数据存储使用的 Leancloud、架构采用 MVP 的记账本 APP。
Java
392
star
3

CalendarView

Android 平台上继承 View 实现的自定义日历控件
Java
134
star
4

DiffuseView

This is a circle on the proliferation of Android custom view.
Java
117
star
5

MPermissionUtils

Android6.0 运行时权限处理工具类
Java
85
star
6

InputCodeLayout

这是一个 Android 上输入验证码的自定义布局
Java
83
star
7

sample-gradle-plugin

🚀 A powerful Gradle Plugin to help you demonstrate your android app.
Java
19
star
8

StateLayout

🌀 A customize multiple state layout for Android.
Kotlin
12
star
9

ChordView

🎸 Android custom view for rendering guitar chord.
Java
11
star
10

VerifyCodeButton

This is a custom button on Android View, used to obtain a verification code.
Java
11
star
11

OKMock

🎈 A Gradle Plugin used to quickly fill field data on Android.
Java
9
star
12

ZProgressBar

一个可动态配置颜色、弧度,带动画的自定义 ProgressBar
Java
8
star
13

TimeLineLayout

This is a simple timeline layout that applies to less data. (这是一个简单的时间轴布局,适用于数据量少的情况)
Java
8
star
14

ImageComparator

🌅 Image comparator on android.
Kotlin
7
star
15

InspireWritingPlugin

🔧 An IntelliJ IDEA plugin is used to inspire you to write code.
Kotlin
6
star
16

android-plugin-template

An android gradle plugin template.
Kotlin
5
star
17

RatingBar

RatingBar on Unity.
C#
3
star
18

CodeStatistics

📈 Code statistic build with tornadofx. supports export excel or csv.
Kotlin
2
star
19

IncrementLint

🔍 A Gradle Plugin that supports Lint increment scanning.
Kotlin
2
star