Android Guides | Samples

Android.Content.Res.ColorStateList Class

Lets you map View state sets to colors.

See Also: ColorStateList

Syntax

[Android.Runtime.Register("android/content/res/ColorStateList", DoNotGenerateAcw=true)]
public class ColorStateList : Object, IParcelable, IDisposable

Remarks

Lets you map View state sets to colors. 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:

xml Example

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_focused="true" android:color="@color/testcolor1"/>
   <item android:state_pressed="true" android:state_enabled="false" android:color="@color/testcolor2" />
   <item android:state_enabled="false" android:color="@color/testcolor3" />
   <item android:color="@color/testcolor5"/>
 </selector>
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. The list of state specs will be processed in order of the items in the XML 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. Note that if you have such an item before any other items in the list then any subsequent items will end up being ignored.

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

[Android Documentation]

Requirements

Namespace: Android.Content.Res
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Content.Res.ColorStateList are listed below.

See Also: Object

Public Constructors

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

Protected Constructors

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

Public Properties

[read-only]
static
CreatorIParcelableCreator.
[read-only]
DefaultColorColor. Return the default color in this ColorStateList.
[read-only]
IsOpaqueBoolean. Indicates whether this color state list is opaque, which means that every color returned from ColorStateList.GetColorForState(Int32[],Color) has an alpha value of 255.
[read-only]
IsStatefulBoolean. Indicates whether this color state list contains more than one state spec and will change color based on state.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

static
CreateFromXml(Resources, XmlReader) : ColorStateList
Creates a ColorStateList from an XML document.
DescribeContents() : Int32
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
GetColorForState(Int32[], Color) : Color
Return the color associated with the given set of View states.
GetColorForState(Int32[], Color) : Int32
Return the color associated with the given set of View states.
static
ValueOf(Color) : ColorStateList
WithAlpha(Int32) : ColorStateList
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).
WriteToParcel(Parcel, ParcelableWriteFlags)
Flatten this object in to a Parcel.