public class MaterialSpinner
extends AppCompatTextView
| Modifier and Type | Class and Description |
|---|---|
static interface |
MaterialSpinner.OnItemSelectedListener<T>
Interface definition for a callback to be invoked when an item in this view has been selected.
|
static interface |
MaterialSpinner.OnNoMoreChoiceListener
无更多选择的监听
|
static interface |
MaterialSpinner.OnNothingSelectedListener
Interface definition for a callback to be invoked when the dropdown is dismissed and no item was selected.
|
| Constructor and Description |
|---|
MaterialSpinner(android.content.Context context) |
MaterialSpinner(android.content.Context context,
android.util.AttributeSet attrs) |
MaterialSpinner(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr) |
| Modifier and Type | Method and Description |
|---|---|
void |
collapse()
Closes the dropdown menu
|
void |
expand()
Show the dropdown menu
|
MaterialSpinnerBaseAdapter |
getAdapter()
获取适配器
|
<T> java.util.List<T> |
getItems()
Get the list of items in the adapter
|
android.widget.ListView |
getListView()
Get the
ListView that is used in the dropdown menu |
android.widget.PopupWindow |
getPopupWindow()
Get the
PopupWindow. |
int |
getSelectedIndex() |
<T> T |
getSelectedItem()
Get the Selected Item in the adapter
|
<T> int |
getSpinnerPosition(T item,
java.util.List<T> items)
获取选中内容在Spinner中的位置
|
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec) |
void |
onRestoreInstanceState(android.os.Parcelable savedState) |
android.os.Parcelable |
onSaveInstanceState() |
boolean |
onTouchEvent(android.view.MotionEvent event) |
MaterialSpinner |
setAdapter(android.widget.ListAdapter adapter)
Set a custom adapter for the dropdown items
|
<T> MaterialSpinner |
setAdapter(MaterialSpinnerAdapter<T> adapter)
Set the custom adapter for the dropdown items
|
void |
setArrowColor(int color)
Set the tint color for the dropdown arrow
|
void |
setBackgroundColor(int color) |
MaterialSpinner |
setDropDownBackgroundSelector(int backgroundSelector) |
void |
setDropdownHeight(int height)
Set the height of the dropdown menu
|
void |
setDropdownMaxHeight(int height)
Set the maximum height of the dropdown menu.
|
void |
setEnabled(boolean enabled) |
<T> MaterialSpinner |
setItems(java.util.List<T> items)
Set the dropdown items
|
<T> MaterialSpinner |
setItems(T... items)
Set the dropdown items
|
MaterialSpinner |
setOnItemSelectedListener(MaterialSpinner.OnItemSelectedListener onItemSelectedListener)
Register a callback to be invoked when an item in the dropdown is selected.
|
MaterialSpinner |
setOnNoMoreChoiceListener(MaterialSpinner.OnNoMoreChoiceListener onNoMoreChoiceListener)
设置无更多选择的监听
|
MaterialSpinner |
setOnNothingSelectedListener(MaterialSpinner.OnNothingSelectedListener onNothingSelectedListener)
Register a callback to be invoked when the
PopupWindow is shown but the user didn't select an item. |
MaterialSpinner |
setSelectedIndex(int position)
Set the default spinner item using its index
|
<T> MaterialSpinner |
setSelectedItem(T item)
设置选中的内容
|
void |
setTextColor(int color) |
public MaterialSpinner(android.content.Context context)
public MaterialSpinner(android.content.Context context,
android.util.AttributeSet attrs)
public MaterialSpinner(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
public boolean onTouchEvent(android.view.MotionEvent event)
public void setBackgroundColor(int color)
public void setTextColor(int color)
public android.os.Parcelable onSaveInstanceState()
public void onRestoreInstanceState(android.os.Parcelable savedState)
public void setEnabled(boolean enabled)
public int getSelectedIndex()
public MaterialSpinner setSelectedIndex(int position)
position - the item's positionpublic <T> MaterialSpinner setSelectedItem(T item)
T - item - 选中的内容public <T> int getSpinnerPosition(T item,
java.util.List<T> items)
item - 选中的内容items - Spinner中选项的集合public MaterialSpinner setOnItemSelectedListener(MaterialSpinner.OnItemSelectedListener onItemSelectedListener)
onItemSelectedListener - The callback that will runpublic MaterialSpinner setOnNothingSelectedListener(MaterialSpinner.OnNothingSelectedListener onNothingSelectedListener)
PopupWindow is shown but the user didn't select an item.onNothingSelectedListener - the callback that will runpublic MaterialSpinner setOnNoMoreChoiceListener(MaterialSpinner.OnNoMoreChoiceListener onNoMoreChoiceListener)
onNoMoreChoiceListener - @SafeVarargs public final <T> MaterialSpinner setItems(T... items)
T - The item typeitems - A list of itemspublic <T> MaterialSpinner setItems(java.util.List<T> items)
T - The item typeitems - A list of itemspublic <T> java.util.List<T> getItems()
T - The item typenull if no items are set.public <T> T getSelectedItem()
T - The item typenull if no items are set.public MaterialSpinner setAdapter(android.widget.ListAdapter adapter)
adapter - The list adapterpublic <T> MaterialSpinner setAdapter(MaterialSpinnerAdapter<T> adapter)
T - The typeadapter - The adapterpublic MaterialSpinnerBaseAdapter getAdapter()
public MaterialSpinner setDropDownBackgroundSelector(int backgroundSelector)
public void expand()
public void collapse()
public void setArrowColor(int color)
color - the color valuepublic void setDropdownMaxHeight(int height)
height - the height in pixelspublic void setDropdownHeight(int height)
height - the height in pixelspublic android.widget.PopupWindow getPopupWindow()
PopupWindow.PopupWindow that is displayed when the view has been clicked.public android.widget.ListView getListView()
ListView that is used in the dropdown menu