added in version 25.1.0
belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1

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
             ↳ android.support.v7.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

From class android.widget.Spinner
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

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 MODE_DIALOG or 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

From class android.widget.Spinner
From class android.widget.AbsSpinner
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.content.DialogInterface.OnClickListener
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.support.v4.view.TintableBackgroundView

Public constructors

AppCompatSpinner

added in version 25.1.0
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 25.1.0
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 MODE_DIALOG or 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 25.1.0
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 25.1.0
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 25.1.0
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 MODE_DIALOG or 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 25.1.0
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 MODE_DIALOG or 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 Spinner_popupTheme.

Public methods

getDropDownHorizontalOffset

int getDropDownHorizontalOffset ()

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

Returns
int Horizontal offset in pixels

getDropDownVerticalOffset

int getDropDownVerticalOffset ()

Returns
int

getDropDownWidth

int getDropDownWidth ()

Returns
int

getPopupBackground

Drawable getPopupBackground ()

Returns
Drawable

getPopupContext

Context getPopupContext ()

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

getPrompt

CharSequence getPrompt ()

Returns
CharSequence

onTouchEvent

boolean onTouchEvent (MotionEvent event)

Parameters
event MotionEvent

Returns
boolean

performClick

boolean performClick ()

Returns
boolean

setAdapter

void setAdapter (SpinnerAdapter adapter)

Parameters
adapter SpinnerAdapter

setBackgroundDrawable

added in version 26.1.0
void setBackgroundDrawable (Drawable background)

Parameters
background Drawable

setBackgroundResource

void setBackgroundResource (int resId)

Parameters
resId int

setDropDownHorizontalOffset

void setDropDownHorizontalOffset (int pixels)

Parameters
pixels int

setDropDownVerticalOffset

void setDropDownVerticalOffset (int pixels)

Parameters
pixels int

setDropDownWidth

void setDropDownWidth (int pixels)

Parameters
pixels int

setPopupBackgroundDrawable

void setPopupBackgroundDrawable (Drawable background)

Parameters
background Drawable

setPopupBackgroundResource

void setPopupBackgroundResource (int resId)

Parameters
resId int

setPrompt

void setPrompt (CharSequence prompt)

Parameters
prompt CharSequence

Protected methods

drawableStateChanged

void drawableStateChanged ()

onDetachedFromWindow

void onDetachedFromWindow ()

onMeasure

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int