ColorStateList Class

Definition

Lets you map android.view.View state sets to colors.

[Android.Runtime.Register("android/content/res/ColorStateList", DoNotGenerateAcw=true)]
public class ColorStateList : Java.Lang.Object, Android.OS.IParcelable, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("android/content/res/ColorStateList", DoNotGenerateAcw=true)>]
type ColorStateList = class
    inherit Object
    interface IParcelable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
ColorStateList
Attributes
Implements

Remarks

Lets you map android.view.View state sets to colors.

android.content.res.ColorStateLists are created from XML resource files defined in the "color" subdirectory directory of an application's resource directory. The XML file contains a single "selector" element with a number of "item" elements inside. For example:

&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
              &lt;item android:state_focused="true"
                      android:color="@color/sample_focused" /&gt;
              &lt;item android:state_pressed="true"
                      android:state_enabled="false"
                      android:color="@color/sample_disabled_pressed" /&gt;
              &lt;item android:state_enabled="false"
                      android:color="@color/sample_disabled_not_pressed" /&gt;
              &lt;item android:color="@color/sample_default" /&gt;
            &lt;/selector&gt;

This defines a set of state spec / color pairs where each state spec specifies a set of states that a view must either be in or not be in and the color specifies the color associated with that spec.

"StateSpec"><h3>State specs</h3>

Each item defines a set of state spec and color pairs, where the state spec is a series of attributes set to either true or false to represent inclusion or exclusion. If an attribute is not specified for an item, it may be any value.

For example, the following item will be matched whenever the focused state is set; any other states may be set or unset:

&lt;item android:state_focused="true"
                    android:color="@color/sample_focused" /&gt;

Typically, a color state list will reference framework-defined state attributes such as android.R.attr#state_focused android:state_focused or android.R.attr#state_enabled android:state_enabled; however, app-defined attributes may also be used.

<strong>Note:</strong> The list of state specs will be matched against in the order that they appear in the XML file. For this reason, more-specific items should be placed earlier in the file. An item with no state spec is considered to match any set of states and is generally useful as a final item to be used as a default.

If an item with no state spec is placed before other items, those items will be ignored.

"ItemAttributes"><h3>Item attributes</h3>

Each item must define an android.R.attr#color android:color attribute, which may be an HTML-style hex color, a reference to a color resource, or -- in API 23 and above -- a theme attribute that resolves to a color.

Starting with API 23, items may optionally define an android.R.attr#alpha android:alpha attribute to modify the base color's opacity. This attribute takes a either floating-point value between 0 and 1 or a theme attribute that resolves as such. The item's overall color is calculated by multiplying by the base color's alpha channel by the alpha value. For example, the following item represents the theme's accent color at 50% opacity:

&lt;item android:state_enabled="false"
                    android:color="?android:attr/colorAccent"
                    android:alpha="0.5" /&gt;

Starting with API 31, items may optionally define an android.R.attr#lStar android:lStar attribute to modify the base color's perceptual luminance. This attribute takes either a floating-point value between 0 and 100 or a theme attribute that resolves as such. The item's overall color is calculated by converting the base color to an accessibility friendly color space and setting its L* to the value specified on the lStar attribute. For example, the following item represents the theme's accent color at 50% perceptual luminance:

&lt;item android:state_enabled="false"
                    android:color="?android:attr/colorAccent"
                    android:lStar="50" /&gt;

"DeveloperGuide"><h3>Developer guide</h3>

For more information, see the guide to Color State List Resource.

Java documentation for android.content.res.ColorStateList.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

ColorStateList(Int32[][], Int32[])

Creates a ColorStateList that returns the specified mapping from states to colors.

ColorStateList(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

ChangingConfigurations

Returns a mask of the configuration parameters for which this color state list may change, requiring that it be re-created.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Creator
DefaultColor

Return the default color in this ColorStateList.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsOpaque

Indicates whether this color state list is opaque, which means that every color returned from #getColorForState(int[], int) has an alpha value of 255.

IsStateful

Indicates whether this color state list contains at least one state spec and the first spec is not empty (e.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CreateFromXml(Resources, XmlReader)

Creates a ColorStateList from an XML document.

CreateFromXml(Resources, XmlReader, Resources+Theme)

Creates a ColorStateList from an XML document.

DescribeContents()

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetColorForState(Int32[], Color)

Return the color associated with the given set of android.view.View states.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
ValueOf(Color)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
WithAlpha(Int32)

Creates a new ColorStateList that has the same states and colors as this one but where each color has the specified alpha value (0-255).

WithLStar(Single)

Creates a new ColorStateList that has the same states and colors as this one but where each color has the specified perceived luminosity value (0-100).

WriteToParcel(Parcel, ParcelableWriteFlags)

Flatten this object in to a Parcel.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to