午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Android如何實現年月選擇器功能

瀏覽:90日期:2022-09-20 11:53:46

開發過程中,年月的選擇功能還是比較常見的,像這種功能點比較常見,要是每次都要自己手動去寫,這無疑會耗費比較多的時間與精力,今天給大家介紹一個第三方庫,使用該庫來完成年月選擇器功能。

一、效果圖

Android如何實現年月選擇器功能

二、實現步驟:1、依賴庫

implementation ’cn.aigestudio.wheelpicker:WheelPicker:1.1.3’2、xml布局文件

<?xml version='1.0' encoding='utf-8'?><android.support.constraint.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' android:layout_width='match_parent' android:layout_height='200dp' android:background='#ffffff'> <TextView android: android:layout_width='60dp' android:layout_height='40dp' android:gravity='center' android:text='取消' android:textColor='#666666' android:textSize='17sp' app:layout_constraintLeft_toLeftOf='parent' app:layout_constraintTop_toTopOf='parent' /> <TextView android: android:layout_width='60dp' android:layout_height='40dp' android:gravity='center' android:text='確定' android:textColor='#3C76FF' android:textSize='17sp' app:layout_constraintRight_toRightOf='parent' app:layout_constraintTop_toTopOf='parent' /> <View android: android:layout_width='match_parent' android:layout_height='1dp' android:background='#e5e5e5' app:layout_constraintLeft_toLeftOf='parent' app:layout_constraintTop_toBottomOf='@id/cancel' /> <com.aigestudio.wheelpicker.WheelPicker android: android:layout_width='0dp' android:layout_height='0dp' android:layout_marginLeft='30dp' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintLeft_toLeftOf='parent' app:layout_constraintRight_toLeftOf='@id/mWheelPicker_2' app:layout_constraintTop_toBottomOf='@id/view_line' app:wheel_atmospheric='true' app:wheel_curtain_color='#1886F7' app:wheel_curved='true' app:wheel_cyclic='true' app:wheel_indicator_color='#e5e5e5' app:wheel_item_text_color='#919191' app:wheel_item_text_size='23sp' app:wheel_selected_item_text_color='#000000' /> <com.aigestudio.wheelpicker.WheelPicker android: android:layout_width='0dp' android:layout_height='0dp' android:layout_marginRight='30dp' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintLeft_toRightOf='@id/mWheelPicker_1' app:layout_constraintRight_toRightOf='parent' app:layout_constraintTop_toTopOf='@id/mWheelPicker_1' app:wheel_atmospheric='true' app:wheel_curtain_color='#1886F7' app:wheel_curved='true' app:wheel_cyclic='true' app:wheel_indicator_color='#e5e5e5' app:wheel_indicator_size='24sp' app:wheel_item_text_color='#919191' app:wheel_item_text_size='23sp' app:wheel_selected_item_text_color='#000000' /></android.support.constraint.ConstraintLayout>3、添加數據

List<String> CEOYEAR = new ArrayList<>(); List<String> CEOMONTH = new ArrayList<>(); for (int i = 2000; i < 2051; i++) { CEOYEAR.add(i + ''); } for (int i = 1; i < 13; i++) { CEOMONTH.add(i + ''); }4、設置選擇器彈出框

/** * @desc : 兩個滾動器 **/ private void showTwoWheelPicker(Context context, final List<String> data1, final List<String> data2, final TwoWheelListener mTwoWheelListener) { final Dialog dialog = getDialog(context); Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM); window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); window.setContentView(R.layout.fragment_sami); final WheelPicker wv1 = window.findViewById(R.id.mWheelPicker_1); final WheelPicker wv2 = window.findViewById(R.id.mWheelPicker_2); wv1.setData(data1); wv2.setData(data2); //取消 window.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); //確定 window.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (mTwoWheelListener != null) { mTwoWheelListener.onOk(data1.get(wv1.getCurrentItemPosition()), data2.get(wv2.getCurrentItemPosition())); } } }); } private Dialog getDialog(Context context) { return new AlertDialog.Builder(context, R.style.RoundCornerDialog).setCancelable(false).show(); } private TwoWheelListener mTwoWheelListener = null; public static interface TwoWheelListener { void onOk(String str1, String str2); }5、設置彈出框dialog樣式

<!--圓角的dialog樣式--> <style name='RoundCornerDialog' parent='@android:style/Theme.Dialog'> <item name='android:windowFrame'>@null</item> <item name='android:windowIsFloating'>true</item> <item name='android:windowIsTranslucent'>true</item> <item name='android:windowNoTitle'>true</item> <item name='android:background'>@android:color/transparent</item> <item name='android:windowBackground'>@android:color/transparent</item> <item name='android:backgroundDimEnabled'>true</item> <item name='android:backgroundDimAmount'>0.6</item></style>6、設置點擊事件彈出

findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showTwoWheelPicker(AppBarLayoutActivity.this, CEOYEAR, CEOMONTH, new TwoWheelListener() { @Override public void onOk(String str1, String str2) { Toast.makeText(AppBarLayoutActivity.this, str1 + '年' + str2 + '日', Toast.LENGTH_SHORT).show(); } }); } });四、總結

這個第三方庫我這里只是做了簡單的介紹,還有更多需求的還是去閱讀第三方庫。

第三方庫地址:

https://github.com/AigeStudio/WheelPicker

到這里就結束啦。

以上就是Android如何實現年月選擇器功能的詳細內容,更多關于Android實現年月選擇器功能的資料請關注好吧啦網其它相關文章!

標簽: Android
相關文章:
主站蜘蛛池模板: 中文字幕精品在线播放 | 视频一区二区在线观看 | 日韩va在线 | 爆操小萝莉 | 亚洲黄色大全 | 精品不卡一区二区 | 日韩精品国产一区 | 欧美日韩专区 | 天堂在线观看中文字幕 | 亚洲 欧美 精品 | 国产真人真事毛片视频 | 国产精品免费久久 | 欧美成人猛片aaaaaaa | 欧美男人天堂 | 国产乱国产乱 | 欧美日韩亚洲综合 | av一区在线播放 | 成人久久久精品国产乱码一区二区 | 精品无人国产偷自产在线 | 国产精品2020 | 久草色视频 | 操碰91 | 91黄在线观看 | 久久青 | 国产福利在线 | 日韩成人精品一区二区 | 一级特黄色片 | 日韩影视一区 | 日韩成人一区 | 午夜成人在线视频 | a级一级黄色片 | 国产成人愉拍精品久久 | 亚洲精品欧美精品 | 日韩不卡二区 | 手机在线成人 | 亚洲一区二区视频在线观看 | 成年人在线观看av | 男女片| 久久精品99国产精 | 大香蕉毛片 | av一级免费|