Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.appcompat:appcompat:1.0.0-rc01

AppCompatSpinner

public class AppCompatSpinner
extends Spinner implements TintableBackgroundView

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<android.widget.SpinnerAdapter>
         ↳ android.widget.AbsSpinner
           ↳ android.widget.Spinner
             ↳ androidx.appcompat.widget.AppCompatSpinner


A Spinner which supports compatible features on older versions of the platform, including:

This will automatically be used when you use Spinner in your layouts. You should only need to manually use this class when writing custom views.

Summary

Inherited constants

Inherited fields

Public constructors

AppCompatSpinner(Context context)

Construct a new spinner with the given context's theme.

AppCompatSpinner(Context context, int mode)

Construct a new spinner with the given context's theme and the supplied mode of displaying choices.

AppCompatSpinner(Context context, AttributeSet attrs)

Construct a new spinner with the given context's theme and the supplied attribute set.

AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr)

Construct a new spinner with the given context's theme, the supplied attribute set, and default style attribute.

AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode)

Construct a new spinner with the given context's theme, the supplied attribute set, and default style.

AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme)

Constructs a new spinner with the given context's theme, the supplied attribute set, default styles, popup mode (one of Spinner.MODE_DIALOG or Spinner.MODE_DROPDOWN), and the context against which the popup should be inflated.

Public methods

int getDropDownHorizontalOffset()

Get the configured horizontal offset in pixels for the spinner's popup window of choices.

int getDropDownVerticalOffset()
int getDropDownWidth()
Drawable getPopupBackground()
Context getPopupContext()
CharSequence getPrompt()
boolean onTouchEvent(MotionEvent event)
boolean performClick()
void setAdapter(SpinnerAdapter adapter)
void setBackgroundDrawable(Drawable background)
void setBackgroundResource(int resId)
void setDropDownHorizontalOffset(int pixels)
void setDropDownVerticalOffset(int pixels)
void setDropDownWidth(int pixels)
void setPopupBackgroundDrawable(Drawable background)
void setPopupBackgroundResource(int resId)
void setPrompt(CharSequence prompt)

Protected methods

void drawableStateChanged()
void onDetachedFromWindow()
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited methods

Public constructors

AppCompatSpinner

added in version 1.0.0
public AppCompatSpinner (Context context)

Construct a new spinner with the given context's theme.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

AppCompatSpinner

added in version 1.0.0
public AppCompatSpinner (Context context, 
                int mode)

Construct a new spinner with the given context's theme and the supplied mode of displaying choices. mode may be one of Spinner.MODE_DIALOG or Spinner.MODE_DROPDOWN.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

mode int: Constant describing how the user will select choices from the spinner.

AppCompatSpinner

added in version 1.0.0
public AppCompatSpinner (Context context, 
                AttributeSet attrs)

Construct a new spinner with the given context's theme and the supplied attribute set.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

AppCompatSpinner

added in version 1.0.0
public AppCompatSpinner (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Construct a new spinner with the given context's theme, the supplied attribute set, and default style attribute.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

AppCompatSpinner

added in version 1.0.0
public AppCompatSpinner (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int mode)

Construct a new spinner with the given context's theme, the supplied attribute set, and default style. mode may be one of Spinner.MODE_DIALOG or Spinner.MODE_DROPDOWN and determines how the user will select choices from the spinner.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

mode int: Constant describing how the user will select choices from the spinner.

AppCompatSpinner

added in version 1.0.0
public AppCompatSpinner (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int mode, 
                Resources.Theme popupTheme)

Constructs a new spinner with the given context's theme, the supplied attribute set, default styles, popup mode (one of Spinner.MODE_DIALOG or Spinner.MODE_DROPDOWN), and the context against which the popup should be inflated.

Parameters
context Context: The context against which the view is inflated, which provides access to the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

mode int: Constant describing how the user will select choices from the spinner.

popupTheme Resources.Theme: The theme against which the dialog or dropdown popup should be inflated. May be null to use the view theme. If set, this will override any value specified by R.styleable.Spinner_popupTheme.

Public methods

getDropDownHorizontalOffset

public int getDropDownHorizontalOffset ()

Get the configured horizontal offset in pixels for the spinner's popup window of choices. Only valid in Spinner.MODE_DROPDOWN; other modes will return 0.

Returns
int Horizontal offset in pixels

getDropDownVerticalOffset

public int getDropDownVerticalOffset ()

Returns
int

getDropDownWidth

public int getDropDownWidth ()

Returns
int

getPopupBackground

public Drawable getPopupBackground ()

Returns
Drawable

getPopupContext

public Context getPopupContext ()

Returns
Context the context used to inflate the Spinner's popup or dialog window

getPrompt

public CharSequence getPrompt ()

Returns
CharSequence

onTouchEvent

public boolean onTouchEvent (MotionEvent event)

Parameters
event MotionEvent

Returns
boolean

performClick

public boolean performClick ()

Returns
boolean

setAdapter

public void setAdapter (SpinnerAdapter adapter)

Parameters
adapter SpinnerAdapter

setBackgroundDrawable

added in version 1.0.0
public void setBackgroundDrawable (Drawable background)

Parameters
background Drawable

setBackgroundResource

public void setBackgroundResource (int resId)

Parameters
resId int

setDropDownHorizontalOffset

public void setDropDownHorizontalOffset (int pixels)

Parameters
pixels int

setDropDownVerticalOffset

public void setDropDownVerticalOffset (int pixels)

Parameters
pixels int

setDropDownWidth

public void setDropDownWidth (int pixels)

Parameters
pixels int

setPopupBackgroundDrawable

public void setPopupBackgroundDrawable (Drawable background)

Parameters
background Drawable

setPopupBackgroundResource

public void setPopupBackgroundResource (int resId)

Parameters
resId int

setPrompt

public void setPrompt (CharSequence prompt)

Parameters
prompt CharSequence

Protected methods

drawableStateChanged

protected void drawableStateChanged ()

onDetachedFromWindow

protected void onDetachedFromWindow ()

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int