一個Material的Spinner

bmid6930 8年前發布 | 11K 次閱讀 Android開發 移動開發

一個Material的Spinner。

使用說明:

把spinner添加進layout xml:

<com.jaredrummler.materialspinner.MaterialSpinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

把items添加進spinner并監聽點擊:

MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spinner);
spinner.setItems("Ice Cream Sandwich", "Jelly Bean", "KitKat", "Lollipop", "Marshmallow");
spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {

  @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
    Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show();
  }
});

你可以為自定義view添加屬性。可用的屬性:

name type info
ms_arrow_tint color sets the color on the drop-down arrow
ms_hide_arrow boolean set to true to hide the arrow drawable
ms_background_color color set the background color for the spinner and drop-down
ms_text_color color set the text color

下載

下載 最新的AAR 或者用Gradle:

compile 'com.jaredrummler:material-spinner:1.0.4'

或者 Maven:

<dependency>
  <groupId>com.jaredrummler</groupId>
  <artifactId>material-spinner</artifactId>
  <version>1.0.4</version>
  <type>aar</type>
</dependency>

感謝

本library基于Angelo Marchesin的 Nice Spinner 。

項目地址: https://github.com/jaredrummler/Material-Spinner

 本文由用戶 bmid6930 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!