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 Boolean

open Unit

open Int

open Unit

open Unit

open CharSequence!

open Unit
setBackgroundResource(@DrawableRes resId: Int)

open Unit

open Boolean

open Int

open Unit

open Unit

open Unit
setPopupBackgroundResource(@DrawableRes resId: Int)

open Context!

open Int

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

open Unit

open Drawable!

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

onTouchEvent

open fun onTouchEvent(event: MotionEvent!): Boolean

setBackgroundDrawable

open fun setBackgroundDrawable(background: Drawable!): Unit

getDropDownVerticalOffset

open fun getDropDownVerticalOffset(): Int

setAdapter

open fun setAdapter(adapter: SpinnerAdapter!): Unit

setDropDownHorizontalOffset

open fun setDropDownHorizontalOffset(pixels: Int): Unit

getPrompt

open fun getPrompt(): CharSequence!

setBackgroundResource

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

setDropDownVerticalOffset

open fun setDropDownVerticalOffset(pixels: Int): Unit

performClick

open fun performClick(): Boolean

getDropDownWidth

open fun getDropDownWidth(): Int

setDropDownWidth

open fun setDropDownWidth(pixels: Int): Unit

setPrompt

open fun setPrompt(prompt: CharSequence!): Unit

setPopupBackgroundResource

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

getPopupContext

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

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

setPopupBackgroundDrawable

open fun setPopupBackgroundDrawable(background: Drawable!): Unit

getPopupBackground

open fun getPopupBackground(): Drawable!

Protected methods

drawableStateChanged

protected open fun drawableStateChanged(): Unit

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onMeasure

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