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、定制
可以添加一些属性进行定制视图. 属性如下:
name | type | info | example |
---|---|---|---|
ms_arrow_tint | 颜色 | 设置箭头的颜色 | app:ms_arrow_tint=”@color/dull_blue” |
ms_hide_arrow | boolean | 设置为true 隐藏箭头绘制 | app:ms_hide_arrow=”true” |
ms_background_color | color | 设置下拉框的颜色 | app:ms_background_color=”@color/spinner_bg” |
ms_background_selector | integer | 下拉元素选中颜色 | 没有这个属性(我试了,收到报错) |
ms_text_color | color | 设置字颜色 | app:ms_text_color=”#ffffff” |
ms_dropdown_max_height | dimension | 设置下拉最大高度 | app:ms_dropdown_max_height=”360dp” |
ms_dropdown_height | dimension | 设置下拉高度 | 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"
/>