Build 1.0_r1(from source)

android.content.res
Class ColorStateList

java.lang.Object
  extended by android.content.res.ColorStateList
All Implemented Interfaces:
Parcelable

public class ColorStateList
extends Object
implements Parcelable

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:

 <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:colore="@color/testcolor3" />
   <item android:state_active="true" android:color="@color/testcolor4" />
   <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.


Nested Class Summary
 
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.Creator<T>
 
Field Summary
static Parcelable.Creator<ColorStateList> CREATOR
           
 
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
 
Constructor Summary
ColorStateList(int[][] states, int[] colors)
          Creates a ColorStateList that returns the specified mapping from states to colors.
 
Method Summary
static ColorStateList createFromXml(Resources r, XmlPullParser parser)
          Create a ColorStateList from an XML document, given a set of Resources.
 int describeContents()
          Describe the kinds of special objects contained in this Parcelable's marshalled representation.
 int getColorForState(int[] stateSet, int defaultColor)
          Return the color associated with the given set of View states.
 int getDefaultColor()
          Return the default color in this ColorStateList.
 boolean isStateful()
           
 String toString()
          Returns a string containing a concise, human-readable description of the receiver.
static ColorStateList valueOf(int color)
          Creates or retrieves a ColorStateList that always returns a single color.
 ColorStateList withAlpha(int alpha)
          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).
 void writeToParcel(Parcel dest, int flags)
          Flatten this object in to a Parcel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CREATOR

public static final Parcelable.Creator<ColorStateList> CREATOR
Constructor Detail

ColorStateList

public ColorStateList(int[][] states,
                      int[] colors)
Creates a ColorStateList that returns the specified mapping from states to colors.

Method Detail

valueOf

public static ColorStateList valueOf(int color)
Creates or retrieves a ColorStateList that always returns a single color.


createFromXml

public static ColorStateList createFromXml(Resources r,
                                           XmlPullParser parser)
                                    throws XmlPullParserException,
                                           IOException
Create a ColorStateList from an XML document, given a set of Resources.

Throws:
XmlPullParserException
IOException

withAlpha

public ColorStateList withAlpha(int alpha)
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).


isStateful

public boolean isStateful()

getColorForState

public int getColorForState(int[] stateSet,
                            int defaultColor)
Return the color associated with the given set of View states.

Parameters:
stateSet - an array of View states
defaultColor - the color to return if there's not state spec in this ColorStateList that matches the stateSet.
Returns:
the color associated with that set of states in this ColorStateList.

getDefaultColor

public int getDefaultColor()
Return the default color in this ColorStateList.

Returns:
the default color in this ColorStateList.

toString

public String toString()
Description copied from class: Object
Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
String a printable representation for the receiver.

describeContents

public int describeContents()
Description copied from interface: Parcelable
Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Specified by:
describeContents in interface Parcelable
Returns:
a bitmask indicating the set of special object types marshalled by the Parcelable.

writeToParcel

public void writeToParcel(Parcel dest,
                          int flags)
Description copied from interface: Parcelable
Flatten this object in to a Parcel.

Specified by:
writeToParcel in interface Parcelable
Parameters:
dest - The Parcel in which the object should be written.
flags - Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature