亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android如何實現(xiàn)年月選擇器功能

 更新時間:2021年03月24日 11:21:06   作者:龍旋  
這篇文章主要介紹了Android如何實現(xiàn)年月選擇器功能,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下

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

一、效果圖

二、實現(xiàn)步驟:

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:id="@+id/cancel"
  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:id="@+id/ok"
  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:id="@+id/view_line"
  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:id="@+id/mWheelPicker_1"
  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:id="@+id/mWheelPicker_2"
  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、添加數(shù)據(jù)

 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、設(shè)置選擇器彈出框

 /**
  * @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、設(shè)置彈出框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、設(shè)置點(diǎn)擊事件彈出

 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();
     }
    });
   }
  });

四、總結(jié)

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

第三方庫地址:

https://github.com/AigeStudio/WheelPicker

到這里就結(jié)束啦。

以上就是Android如何實現(xiàn)年月選擇器功能的詳細(xì)內(nèi)容,更多關(guān)于Android實現(xiàn)年月選擇器功能的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 學(xué)習(xí)Android Handler消息傳遞機(jī)制

    學(xué)習(xí)Android Handler消息傳遞機(jī)制

    這篇文章主要為大家詳細(xì)介紹了Android Handler消息傳遞機(jī)制,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android使用BroadcastReceiver實現(xiàn)手機(jī)開機(jī)之后顯示畫面的功能

    Android使用BroadcastReceiver實現(xiàn)手機(jī)開機(jī)之后顯示畫面的功能

    這篇文章主要介紹了Android使用BroadcastReceiver實現(xiàn)手機(jī)開機(jī)之后顯示畫面的功能,結(jié)合實例形式分析了BroadcastReceiver的具體使用技巧及實現(xiàn)開機(jī)畫面的相關(guān)功能代碼,需要的朋友可以參考下
    2016-01-01
  • Android 浮動編輯框的具體實現(xiàn)代碼

    Android 浮動編輯框的具體實現(xiàn)代碼

    本篇文章主要介紹了Android 浮動編輯框的具體實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • android隱式意圖激活瀏覽器的實現(xiàn)方法

    android隱式意圖激活瀏覽器的實現(xiàn)方法

    下面小編就為大家?guī)硪黄猘ndroid隱式意圖激活瀏覽器的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • 仿餓了嗎點(diǎn)餐界面ListView聯(lián)動的實現(xiàn)

    仿餓了嗎點(diǎn)餐界面ListView聯(lián)動的實現(xiàn)

    這篇文章主要介紹了仿餓了嗎點(diǎn)餐界面ListView聯(lián)動的實現(xiàn)的相關(guān)資料,本文介紹的非常詳細(xì),具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09
  • Android Bitmap和Drawable相互轉(zhuǎn)換的簡單代碼

    Android Bitmap和Drawable相互轉(zhuǎn)換的簡單代碼

    Android Bitmap和Drawable相互轉(zhuǎn)換的簡單代碼,需要的朋友可以參考一下
    2013-05-05
  • Android延時操作的三種方法

    Android延時操作的三種方法

    這篇文章主要為大家詳細(xì)介紹了Android延時操作的三種方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • listview 選中高亮顯示實現(xiàn)方法

    listview 選中高亮顯示實現(xiàn)方法

    當(dāng)點(diǎn)擊左側(cè)ListView后,選中的一行就會一直呈高亮狀態(tài)顯示,圖中選中行字的顏色顯示為藍(lán)色(注意:是選中行后一直高亮,而不是只是點(diǎn)擊時高亮),如果再次點(diǎn)擊另外的一行, 則新的那一行就高亮,下面就來實現(xiàn)這個高亮效果的顯示
    2012-11-11
  • Android實現(xiàn)隨手指移動小球

    Android實現(xiàn)隨手指移動小球

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)隨手指移動小球,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • 21天學(xué)習(xí)android開發(fā)教程之XML解析與生成

    21天學(xué)習(xí)android開發(fā)教程之XML解析與生成

    21天學(xué)習(xí)android開發(fā)教程之XML解析與生成,使用SAX來解析XML,在Android里面可以使用SAX和DOM,DOM需要把整個XML文件讀入內(nèi)存再解析,比較消耗內(nèi)存,而SAX基于事件驅(qū)動的處理方式,可以在各節(jié)點(diǎn)觸發(fā)回調(diào)函數(shù),需要的朋友可以參考下
    2016-02-02

最新評論