├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── app-release.apk │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── teapickerview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── teapickerview │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── teapickerview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image └── hn2u5-ukvzr.gif ├── pickerviewlibrary ├── .gitignore ├── build.gradle ├── libs │ └── gson-2.3-sources.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── pickerviewlibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── pickerviewlibrary │ │ │ └── picker │ │ │ ├── TeaPickerView.java │ │ │ ├── adapter │ │ │ └── DataAdapter.java │ │ │ ├── entity │ │ │ ├── PickerData.java │ │ │ ├── ProvinceBean.java │ │ │ ├── SecondBean.java │ │ │ └── ThirdBean.java │ │ │ ├── listener │ │ │ └── OnPickerClickListener.java │ │ │ └── util │ │ │ └── JsonArrayUtil.java │ └── res │ │ ├── anim │ │ ├── slide_in_from_bottom.xml │ │ └── slide_out_to_bottom.xml │ │ ├── color │ │ └── text_selecter.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── ic_quality_selected.png │ │ ├── layout_sharp.xml │ │ └── tab_sharp.xml │ │ ├── layout │ │ ├── data_textview.xml │ │ └── picker_view.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── pickerviewlibrary │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TeaPickerView 2 | 3 | ![这是一张图片](https://github.com/YangsBryant/TeaPickerView/blob/master/image/hn2u5-ukvzr.gif) 4 | 5 | ## 引入module 6 | ```java 7 | allprojects { 8 | repositories { 9 | google() 10 | jcenter() 11 | maven { url 'https://www.jitpack.io' } 12 | } 13 | } 14 | ``` 15 | ```java 16 | implementation 'com.github.YangsBryant:TeaPickerView:1.0.2' 17 | ``` 18 | 19 | ## 主要代码 20 | 21 | ```java 22 | public class MainActivity extends AppCompatActivity { 23 | 24 | @BindView(R.id.mButton) 25 | Button button; 26 | 27 | List mProvinceDatas=new ArrayList<>(); 28 | Map> mSecondDatas= new HashMap<>(); 29 | Map> mThirdDatas= new HashMap<>(); 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_main); 34 | ButterKnife.bind( this ); 35 | intiPickerView(); 36 | } 37 | 38 | private void intiPickerView(){ 39 | //一级列表 40 | ProvinceBean provinceBean = new ProvinceBean(); 41 | mProvinceDatas.addAll(provinceBean.getRepData().getProvince()); 42 | 43 | //二级列表 44 | SecondBean secondBean = new SecondBean(); 45 | mSecondDatas.putAll(secondBean.getRepData().getSecond()); 46 | 47 | //三级列表 48 | ThirdBean thirdBean = new ThirdBean(); 49 | mThirdDatas.putAll(thirdBean.getRepData().getThird()); 50 | 51 | Log.i("json", JsonArrayUtil.toJson(mProvinceDatas)); 52 | Log.i("json",JsonArrayUtil.toJson(mSecondDatas)); 53 | Log.i("json",JsonArrayUtil.toJson(mThirdDatas)); 54 | 55 | //设置数据有多少层级 56 | PickerData data=new PickerData(); 57 | data.setFirstDatas(mProvinceDatas);//json: ["广东","江西"] 58 | data.setSecondDatas(mSecondDatas);//json: {"江西":["南昌","赣州"],"广东":["广州","深圳","佛山","东莞"]} 59 | data.setThirdDatas(mThirdDatas);//json: {"广州":["天河区","白云区","番禹区","花都区"],"赣州":["章贡区","黄金开发区"],"东莞":["东城","南城"],"深圳":["南山区","宝安区","龙华区"],"佛山":["禅城区","顺德区"],"南昌":["东湖区","青云谱区","青山湖区"]} 60 | 61 | data.setInitSelectText("请选择"); 62 | 63 | TeaPickerView teaPickerView =new TeaPickerView(this,data); 64 | teaPickerView.setScreenH(3) 65 | .setDiscolourHook(true) 66 | .setRadius(25) 67 | .setContentLine(true) 68 | .setRadius(25) 69 | .build(); 70 | 71 | button.setOnClickListener(v -> { 72 | //显示选择器 73 | teaPickerView.show(button); 74 | }); 75 | 76 | //选择器点击事件 77 | teaPickerView.setOnPickerClickListener(pickerData -> { 78 | Toast.makeText(MainActivity.this,pickerData.getFirstText()+","+pickerData.getSecondText()+","+pickerData.getThirdText(),Toast.LENGTH_SHORT).show(); 79 | teaPickerView.dismiss();//关闭选择器 80 | }); 81 | } 82 | } 83 | ``` 84 | 85 | ## TeaPickerView属性大全 86 | 方法名 | 属性 87 | --------- | ------------- 88 | setHeights(int mHeight) | 显示具体的高度(dp),设置0是自适应(高度没有默认值,需要主动设置) 89 | setScreenH(int num) | 显示的高度占屏幕的百分比 90 | setBackground(int color) | 设置整体的背景颜色 默认是#ffffff 91 | setRadius(int mRadius) | 设置圆角,默认0 92 | setContentBackground(int color) | 内容栏的背景颜色 默认是#ffffff 93 | setContentHeight(int mHeight) | 内容栏的高度(dp) 默认是50dp 94 | setContentText(int size,int color) | 内容栏字体的大小和颜色, 默认是16sp,#0aa666,用此方法会固定颜色 95 | setContentText(ColorStateList drawable) | 自定义内容栏字体颜色变换器 在res目录下创建color文件夹用selector 默认颜色#555 选中颜色#0aa666 96 | setContentLine(boolean bl) | 内容栏选中是否有下划线 默认不开启 97 | setContentLineColor(Drawable drawable) | 自定义内容栏下划线用layer-list 默认是下边框描边 颜色#0fbc72 高度1dp 98 | setLine(int mHeight,int color) | 分割线的高度和颜色 默认是0.5dp #e5e5e5 99 | setitemHeight(int mHeight) | 设置list的item的高度(dp) 默认是40dp 100 | setListText(int size,int color) | 设置list的字体大小和颜色 默认是15 #555 101 | setScrollBal(boolean bl) | 设置list是否显示滚动条,默认false 102 | setAlpha(float mFloat) | 设置阴影层的透明度 默认是0.5f 103 | setDiscolour(boolean bl) | 设置选中项是否加色,默认true 104 | setDiscolourColor(int color) | 设置选中项加色的颜色值,默认#0aa666 105 | setDiscolourHook(boolean bl) | 设置选中项是否有√图标,默认false 106 | setCustomHook(Drawable drawable) | 自定义√图标 107 | build() | 参数设置完毕,一定要build一下 108 | 109 | 方法名 | 属性 110 | --------- | ------------- 111 | setInitSelectText(String firstText) | 初始文字 112 | setFirstDatas(List mFirstDatas) | 设置一级数据 113 | setSecondDatas(Map> mSecondDatas) | 设置二级数据 114 | setThirdDatas(Map> mThirdDatas) | 设置三级数据 115 | setFourthDatas(Map> mFourthDatas) | 设置四级数据 116 | 117 | ## 给出参考bean地址 118 | [一级ProvinceBean](https://github.com/YangsBryant/TeaPickerView/blob/master/pickerviewlibrary/src/main/java/com/example/pickerviewlibrary/picker/entity/ProvinceBean.java) [二级SecondBean](https://github.com/YangsBryant/TeaPickerView/blob/master/pickerviewlibrary/src/main/java/com/example/pickerviewlibrary/picker/entity/SecondBean.java) [三级ThirdBean](https://github.com/YangsBryant/TeaPickerView/blob/master/pickerviewlibrary/src/main/java/com/example/pickerviewlibrary/picker/entity/ThirdBean.java) 119 | 120 | ## 默认内容栏字体颜色变换器 121 | ```java 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | ``` 131 | ## 默认内容栏下划线 132 | ```java 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | ``` 148 | 149 | ## 联系QQ:961606042 150 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.example.teapickerview" 7 | minSdkVersion 22 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_1_8 22 | targetCompatibility JavaVersion.VERSION_1_8 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(include: ['*.jar'], dir: 'libs') 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | implementation project(path: ':pickerviewlibrary') 34 | //butterknife 35 | implementation 'com.jakewharton:butterknife:8.8.1' 36 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YangsBryant/TeaPickerView/fe9ecc8897894af8b1edda7829cb7663e9ac1077/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/teapickerview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.teapickerview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.teapickerview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/teapickerview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.teapickerview; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.widget.Button; 7 | import android.widget.Toast; 8 | import com.example.pickerviewlibrary.picker.TeaPickerView; 9 | import com.example.pickerviewlibrary.picker.entity.PickerData; 10 | import com.example.pickerviewlibrary.picker.entity.ProvinceBean; 11 | import com.example.pickerviewlibrary.picker.entity.SecondBean; 12 | import com.example.pickerviewlibrary.picker.entity.ThirdBean; 13 | import com.example.pickerviewlibrary.picker.util.JsonArrayUtil; 14 | import java.util.ArrayList; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | import butterknife.BindView; 19 | import butterknife.ButterKnife; 20 | 21 | public class MainActivity extends AppCompatActivity { 22 | 23 | @BindView(R.id.mButton) 24 | Button button; 25 | 26 | List mProvinceDatas=new ArrayList<>(); 27 | Map> mSecondDatas= new HashMap<>(); 28 | Map> mThirdDatas= new HashMap<>(); 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_main); 34 | ButterKnife.bind( this ); 35 | intiPickerView(); 36 | } 37 | 38 | private void intiPickerView(){ 39 | //一级列表 40 | ProvinceBean provinceBean = new ProvinceBean(); 41 | mProvinceDatas.addAll(provinceBean.getRepData().getProvince()); 42 | 43 | //二级列表 44 | SecondBean secondBean = new SecondBean(); 45 | mSecondDatas.putAll(secondBean.getRepData().getSecond()); 46 | 47 | //三级列表 48 | ThirdBean thirdBean = new ThirdBean(); 49 | mThirdDatas.putAll(thirdBean.getRepData().getThird()); 50 | 51 | Log.i("json", JsonArrayUtil.toJson(mProvinceDatas)); 52 | Log.i("json",JsonArrayUtil.toJson(mSecondDatas)); 53 | Log.i("json",JsonArrayUtil.toJson(mThirdDatas)); 54 | 55 | //设置数据有多少层级 56 | PickerData data=new PickerData(); 57 | data.setFirstDatas(mProvinceDatas);//json: ["广东","江西"] 58 | data.setSecondDatas(mSecondDatas);//json: {"江西":["南昌","赣州"],"广东":["广州","深圳","佛山","东莞"]} 59 | data.setThirdDatas(mThirdDatas);//json: {"广州":["天河区","白云区","番禹区","花都区"],"赣州":["章贡区","黄金开发区"],"东莞":["东城","南城"],"深圳":["南山区","宝安区","龙华区"],"佛山":["禅城区","顺德区"],"南昌":["东湖区","青云谱区","青山湖区"]} 60 | 61 | data.setInitSelectText("请选择"); 62 | 63 | TeaPickerView pickerView=new TeaPickerView(this,data); 64 | pickerView.setScreenH(3) 65 | .setDiscolourHook(true) 66 | .setRadius(25) 67 | .setContentLine(true) 68 | .setRadius(25) 69 | .build(); 70 | 71 | button.setOnClickListener(v -> { 72 | //显示选择器 73 | pickerView.show(button); 74 | }); 75 | 76 | //选择器点击事件 77 | pickerView.setOnPickerClickListener(pickerData -> { 78 | Toast.makeText(MainActivity.this,pickerData.getFirstText()+","+pickerData.getSecondText()+","+pickerData.getThirdText(),Toast.LENGTH_SHORT).show(); 79 | pickerView.dismiss();//关闭选择器 80 | }); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |