Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [XML Attrs](https://developer.android.com/reference/android/animation/StateListAnimator#lattrs) \| [Ctors](https://developer.android.com/reference/android/animation/StateListAnimator#pubctors) \| [Methods](https://developer.android.com/reference/android/animation/StateListAnimator#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/animation/StateListAnimator#inhmethods)

# StateListAnimator

*** ** * ** ***


`
public


class
StateListAnimator
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/lang/Cloneable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.animation.StateListAnimator |

<br />

*** ** * ** ***

Lets you define a number of Animators that will run on the attached View depending on the View's
drawable state.


It can be defined in an XML file with the `<selector>` element.
Each State Animator is defined in a nested `<item>` element.

## Summary

| ### XML attributes ||
|---|---|
| [`android:animation`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:animation) | Animation to use on each child. |
| [`android:state_activated`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_activated) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view or its parent has been "activated" meaning the user has currently marked it as being of interest. |
| [`android:state_active`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_active) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view or drawable is considered "active" by its host. |
| [`android:state_checkable`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_checkable) | State identifier indicating that the object <var translate="no">may</var> display a check mark. |
| [`android:state_checked`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_checked) | State identifier indicating that the object is currently checked. |
| [`android:state_enabled`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_enabled) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view is enabled. |
| [`android:state_first`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_first) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view or drawable is in the first position in an ordered set. |
| [`android:state_focused`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_focused) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view has input focus. |
| [`android:state_last`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_last) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view or drawable is in the last position in an ordered set. |
| [`android:state_middle`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_middle) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view or drawable is in the middle position in an ordered set. |
| [`android:state_pressed`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_pressed) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when the user is pressing down in a view. |
| [`android:state_selected`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_selected) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view (or one of its parents) is currently selected. |
| [`android:state_single`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_single) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view or drawable is considered "single" by its host. |
| [`android:state_window_focused`](https://developer.android.com/reference/android/animation/StateListAnimator#attr_android:state_window_focused) | State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`, set when a view's window has input focus. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/animation/StateListAnimator#StateListAnimator()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/animation/StateListAnimator#addState(int[],%20android.animation.Animator)(int[] specs, https://developer.android.com/reference/android/animation/Animator animator) ` Associates the given animator with the provided drawable state specs so that it will be run when the View's drawable state matches the specs. |
| ` https://developer.android.com/reference/android/animation/StateListAnimator` | ` https://developer.android.com/reference/android/animation/StateListAnimator#clone()() ` Creates and returns a copy of this object. |
| ` void` | ` https://developer.android.com/reference/android/animation/StateListAnimator#jumpToCurrentState()() ` If there is an animation running for a recent state change, ends it. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## XML attributes

### android:animation

Animation to use on each child.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

### android:state_activated

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view or its parent has been "activated" meaning the user has currently
marked it as being of interest. This is an alternative representation of
state_checked for when the state should be propagated down the view hierarchy.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_active

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view or drawable is considered "active" by its host. Actual usage may vary
between views. Consult the host view documentation for details.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_checkable

State identifier indicating that the object <var translate="no">may</var> display a check mark. See
`https://developer.android.com/reference/android/R.attr#state_checked` for the identifier that indicates whether it is
actually checked.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_checked

State identifier indicating that the object is currently checked. See
`https://developer.android.com/reference/android/R.attr#state_checkable` for an additional identifier that can indicate
if any object may ever display a check, regardless of whether state_checked is
currently set.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_enabled

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view is enabled.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_first

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view or drawable is in the first position in an ordered set. Actual usage
may vary between views. Consult the host view documentation for details.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_focused

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view has input focus.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_last

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view or drawable is in the last position in an ordered set. Actual usage
may vary between views. Consult the host view documentation for details.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_middle

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view or drawable is in the middle position in an ordered set. Actual usage
may vary between views. Consult the host view documentation for details.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_pressed

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when the user is pressing down in a view.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_selected

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view (or one of its parents) is currently selected.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_single

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view or drawable is considered "single" by its host. Actual usage may vary
between views. Consult the host view documentation for details.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:state_window_focused

State value for `https://developer.android.com/reference/android/graphics/drawable/StateListDrawable`,
set when a view's window has input focus.

May be a boolean value, such as "`true`" or
"`false`".

<br />

## Public constructors

### StateListAnimator

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StateListAnimator ()
```

<br />

<br />

## Public methods

### addState

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addState (int[] specs, 
                Animator animator)
```

Associates the given animator with the provided drawable state specs so that it will be run
when the View's drawable state matches the specs.

<br />

| Parameters ||
|---|---|
| `specs` | `int`: The drawable state specs to match against <br /> |
| `animator` | `Animator`: The animator to run when the specs match <br /> |

### clone

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StateListAnimator clone ()
```

Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object `x`, the expression:
>
> ```
> x.clone() != x
> ```
will be true, and that the expression:
>
> ```
> x.clone().getClass() == x.getClass()
> ```
will be `true`, but these are not absolute requirements. While it is typically the case that:
>
> ```
> x.clone().equals(x)
> ```
will be `true`, this is not an absolute requirement.


By convention, the returned object should be obtained by calling
`super.clone`. If a class and all of its superclasses (except
`Object`) obey this convention, it will be the case that
`x.clone().getClass() == x.getClass()`.


By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by `super.clone` before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by `super.clone`
need to be modified.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/animation/StateListAnimator` | a clone of this instance. <br /> |

### jumpToCurrentState

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void jumpToCurrentState ()
```

If there is an animation running for a recent state change, ends it.


This causes the animation to assign the end value(s) to the View.

<br />