Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

AppCompatSpinner

open class AppCompatSpinner : Spinner, TintableBackgroundView
kotlin.Any
   ↳ 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:

  • Allows dynamic tint of its background via the background tint methods in androidx.core.view.ViewCompat.
  • Allows setting of the background tint using R.attr#buttonTint and R.attr#buttonTintMode.
  • Setting the popup theme using R.attr#popupTheme.

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

Public constructors
<init>(context: Context!)

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

<init>(context: Context!, mode: Int)

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

<init>(context: Context!, attrs: AttributeSet!)

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

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

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

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, mode: Int)

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

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, mode: Int, popupTheme: Theme!)

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
open Int

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

open Int

open Int

open Drawable!

open Context!

open CharSequence!

open Unit

open Parcelable!

open Boolean

open Boolean

open Unit

open Unit

open Unit
setBackgroundResource(@DrawableRes resId: Int)

open Unit

open Unit

open Unit

open Unit

open Unit
setPopupBackgroundResource(@DrawableRes resId: Int)

open Unit

Protected methods
open Unit

open Unit

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Public constructors

<init>

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.

<init>

AppCompatSpinner(context: Context!, mode: Int)

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 Context!: Constant describing how the user will select choices from the spinner.

<init>

AppCompatSpinner(context: Context!, attrs: AttributeSet!)

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 Context!: The attributes of the XML tag that is inflating the view.

<init>

AppCompatSpinner(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

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 Context!: The attributes of the XML tag that is inflating the view.
defStyleAttr Context!: 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.

<init>

AppCompatSpinner(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, mode: Int)

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 Context!: The attributes of the XML tag that is inflating the view.
defStyleAttr Context!: 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 Context!: Constant describing how the user will select choices from the spinner.

<init>

AppCompatSpinner(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, mode: Int, popupTheme: Theme!)

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 Context!: The attributes of the XML tag that is inflating the view.
defStyleAttr Context!: 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 Context!: Constant describing how the user will select choices from the spinner.
popupTheme Context!: 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

open fun getDropDownHorizontalOffset(): Int

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.

Return
Int: Horizontal offset in pixels

getDropDownVerticalOffset

open fun getDropDownVerticalOffset(): Int

getDropDownWidth

open fun getDropDownWidth(): Int

getPopupBackground

open fun getPopupBackground(): Drawable!

getPopupContext

open fun getPopupContext(): Context!
Return
Context!: the context used to inflate the Spinner's popup or dialog window

getPrompt

open fun getPrompt(): CharSequence!

onRestoreInstanceState

open fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

open fun onSaveInstanceState(): Parcelable!

onTouchEvent

open fun onTouchEvent(event: MotionEvent!): Boolean

performClick

open fun performClick(): Boolean

setAdapter

open fun setAdapter(adapter: SpinnerAdapter!): Unit

setBackgroundDrawable

open fun setBackgroundDrawable(background: Drawable!): Unit

setBackgroundResource

open fun setBackgroundResource(@DrawableRes resId: Int): Unit

setDropDownHorizontalOffset

open fun setDropDownHorizontalOffset(pixels: Int): Unit

setDropDownVerticalOffset

open fun setDropDownVerticalOffset(pixels: Int): Unit

setDropDownWidth

open fun setDropDownWidth(pixels: Int): Unit

setPopupBackgroundDrawable

open fun setPopupBackgroundDrawable(background: Drawable!): Unit

setPopupBackgroundResource

open fun setPopupBackgroundResource(@DrawableRes resId: Int): Unit

setPrompt

open fun setPrompt(prompt: CharSequence!): Unit

Protected methods

drawableStateChanged

protected open fun drawableStateChanged(): Unit

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onMeasure

protected open fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit