Android 中TeaPickerView數(shù)據(jù)級聯(lián)選擇器功能的實(shí)例代碼
Github地址
(Github排版比較好,建議進(jìn)入這里查看詳情,如果覺得好,點(diǎn)個star吧!)
引入module
allprojects { repositories { google() jcenter() maven { url 'https://www.jitpack.io' } } } implementation 'com.github.YangsBryant:TeaPickerView:1.0.2'
主要代碼
public class MainActivity extends AppCompatActivity { @BindView(R.id.mButton) Button button; List<String> mProvinceDatas=new ArrayList<>(); Map<String, List<String>> mSecondDatas= new HashMap<>(); Map<String, List<String>> mThirdDatas= new HashMap<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind( this ); intiPickerView(); } private void intiPickerView(){ //一級列表 ProvinceBean provinceBean = new ProvinceBean(); mProvinceDatas.addAll(provinceBean.getRepData().getProvince()); //二級列表 SecondBean secondBean = new SecondBean(); mSecondDatas.putAll(secondBean.getRepData().getSecond()); //三級列表 ThirdBean thirdBean = new ThirdBean(); mThirdDatas.putAll(thirdBean.getRepData().getThird()); Log.i("json", JsonArrayUtil.toJson(mProvinceDatas)); Log.i("json",JsonArrayUtil.toJson(mSecondDatas)); Log.i("json",JsonArrayUtil.toJson(mThirdDatas)); //設(shè)置數(shù)據(jù)有多少層級 PickerData data=new PickerData(); data.setFirstDatas(mProvinceDatas);//json: ["廣東","江西"] data.setSecondDatas(mSecondDatas);//json: {"江西":["南昌","贛州"],"廣東":["廣州","深圳","佛山","東莞"]} data.setThirdDatas(mThirdDatas);//json: {"廣州":["天河區(qū)","白云區(qū)","番禹區(qū)","花都區(qū)"],"贛州":["章貢區(qū)","黃金開發(fā)區(qū)"],"東莞":["東城","南城"],"深圳":["南山區(qū)","寶安區(qū)","龍華區(qū)"],"佛山":["禪城區(qū)","順德區(qū)"],"南昌":["東湖區(qū)","青云譜區(qū)","青山湖區(qū)"]} data.setInitSelectText("請選擇"); TeaPickerView teaPickerView =new TeaPickerView(this,data); teaPickerView.setScreenH(3) .setDiscolourHook(true) .setRadius(25) .setContentLine(true) .setRadius(25) .build(); button.setOnClickListener(v -> { //顯示選擇器 teaPickerView.show(button); }); //選擇器點(diǎn)擊事件 teaPickerView.setOnPickerClickListener(pickerData -> { Toast.makeText(MainActivity.this,pickerData.getFirstText()+","+pickerData.getSecondText()+","+pickerData.getThirdText(),Toast.LENGTH_SHORT).show(); teaPickerView.dismiss();//關(guān)閉選擇器 }); } }
TeaPickerView屬性大全
方法名 |
屬性 |
setHeights(int mHeight) |
顯示具體的高度(dp),設(shè)置0是自適應(yīng)(高度沒有默認(rèn)值,需要主動設(shè)置) |
setScreenH(int num) | 顯示的高度占屏幕的百分比 |
setBackground(int color) | 設(shè)置整體的背景顏色 默認(rèn)是#ffffff |
setRadius(int mRadius) | 設(shè)置圓角,默認(rèn)0 |
setContentBackground(int color) | 內(nèi)容欄的背景顏色 默認(rèn)是#ffffff |
setContentHeight(int mHeight) | 內(nèi)容欄的高度(dp) 默認(rèn)是50dp |
setContentText(int size,int color) | 內(nèi)容欄字體的大小和顏色, 默認(rèn)是16sp,#0aa666,用此方法會固定顏色 |
setContentText(ColorStateList drawable) | 自定義內(nèi)容欄字體顏色變換器 在res目錄下創(chuàng)建color文件夾用selector 默認(rèn)顏色#555 選中顏色#0aa666 |
setContentLine(boolean bl) | 內(nèi)容欄選中是否有下劃線 默認(rèn)不開啟 |
setContentLineColor(Drawable drawable) | 自定義內(nèi)容欄下劃線用layer-list 默認(rèn)是下邊框描邊 顏色#0fbc72 高度1dp |
setLine(int mHeight,int color) | 分割線的高度和顏色 默認(rèn)是0.5dp #e5e5e5 |
setitemHeight(int mHeight) | 設(shè)置list的item的高度(dp) 默認(rèn)是40dp |
setListText(int size,int color) | 設(shè)置list的字體大小和顏色 默認(rèn)是15 #555 |
setScrollBal(boolean bl) | 設(shè)置list是否顯示滾動條,默認(rèn)false |
setAlpha(float mFloat) | 設(shè)置陰影層的透明度 默認(rèn)是0.5f |
setDiscolour(boolean bl) | 設(shè)置選中項(xiàng)是否加色,默認(rèn)true |
setDiscolourColor(int color) | 設(shè)置選中項(xiàng)加色的顏色值,默認(rèn)#0aa666 |
setDiscolourHook(boolean bl) | 設(shè)置選中項(xiàng)是否有√圖標(biāo),默認(rèn)false |
setCustomHook(Drawable drawable) | 自定義√圖標(biāo) |
build() | 參數(shù)設(shè)置完畢,一定要build |
設(shè)置數(shù)據(jù)
方法名 | 屬性 |
setInitSelectText(String firstText) | 初始文字 |
setFirstDatas(List mFirstDatas) | 設(shè)置一級數(shù)據(jù) |
setSecondDatas(Map<String, List> mSecondDatas) | 設(shè)置二級數(shù)據(jù) |
setThirdDatas(Map<String, List> mThirdDatas) | 設(shè)置三級數(shù)據(jù) |
setFourthDatas(Map<String, List> mFourthDatas) |
給出參考bean地址
默認(rèn)內(nèi)容欄字體顏色變換器
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/picker_select_text_color"/> <item android:state_pressed="true" android:color="@color/picker_select_text_color"/> <item android:state_checked="true" android:color="@color/picker_select_text_color"/> <item android:state_focused="true" android:color="@color/picker_select_text_color"/> <item android:color="@color/picker_text_color"/> </selector>
默認(rèn)內(nèi)容欄下劃線
<?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 邊框顏色值 --> <item> <shape> <solid android:color="@color/station_average" /> </shape> </item> <item android:bottom="1dp"> <!--設(shè)置只有底部有邊框--> <shape> <solid android:color="#ffffff" /> </shape> </item> </layer-list>
總結(jié)
以上所述是小編給大家介紹的Android 中TeaPickerView數(shù)據(jù)級聯(lián)選擇器功能的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android判斷設(shè)備網(wǎng)絡(luò)連接狀態(tài)及判斷連接方式的方法
這篇文章主要介紹了Android判斷設(shè)備網(wǎng)絡(luò)連接狀態(tài)及判斷連接方式的方法,涉及Android針對網(wǎng)絡(luò)連接的相關(guān)判定技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10Gradle學(xué)習(xí)教程之部署上傳項(xiàng)目詳解
這篇文章主要給大家介紹了關(guān)于Gradle學(xué)習(xí)教程之部署上傳項(xiàng)目的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04Android實(shí)現(xiàn)與Apache Tomcat服務(wù)器數(shù)據(jù)交互(MySql數(shù)據(jù)庫)
本篇文章主要介紹了Android實(shí)現(xiàn)與Apache Tomcat服務(wù)器數(shù)據(jù)交互(MySql數(shù)據(jù)庫),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06Android開發(fā)兩個activity之間傳值示例詳解
這篇文章主要為大家介紹了Android開發(fā)兩個activity之間傳值示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07Android SQLite數(shù)據(jù)庫操作代碼類分享
這篇文章主要介紹了Android SQLite數(shù)據(jù)庫操作代碼類分享,本文直接給出實(shí)現(xiàn)代碼和使用代碼,需要的朋友可以參考下2015-03-03Kotlin利用Regex如何構(gòu)建正則表達(dá)式詳解
正則表達(dá)式,又稱規(guī)則表達(dá)式。下面這篇文章主要給大家介紹了關(guān)于Kotlin利用Regex構(gòu)建正則表達(dá)式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-12-12