做个插件MaterialSpinner笔记

伯君浩
2023-12-01

https://github.com/jaredrummler/MaterialSpinner
1、导包

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

2、用

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

3、装数据

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

4、定制
可以添加一些属性进行定制视图. 属性如下:

nametypeinfoexample
ms_arrow_tint颜色设置箭头的颜色app:ms_arrow_tint=”@color/dull_blue”
ms_hide_arrowboolean设置为true 隐藏箭头绘制app:ms_hide_arrow=”true”
ms_background_colorcolor设置下拉框的颜色app:ms_background_color=”@color/spinner_bg”
ms_background_selectorinteger下拉元素选中颜色没有这个属性(我试了,收到报错)
ms_text_colorcolor设置字颜色app:ms_text_color=”#ffffff”
ms_dropdown_max_heightdimension设置下拉最大高度app:ms_dropdown_max_height=”360dp”
ms_dropdown_heightdimension设置下拉高度app:ms_dropdown_height=”160dp”
 <com.jaredrummler.materialspinner.MaterialSpinner
     android:id="@+id/spinner"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_weight="1"
     android:background="@null"
     app:ms_background_color="@color/spinner_bg"
     app:ms_hide_arrow="true"
     app:ms_text_color="#ffffff"
     />
 类似资料: