Define a color state list

suggest change

Color state lists can be used as colors, but will change depending on the state of the view they are used for.

To define one, create a resource file in res/color/foo.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#888888" android:state_enabled="false"/>
    <item android:color="@color/lightGray" android:state_selected="false"/>
    <item android:color="@android:color/white" />
</selector>

Items are evaluated in order, and the first item whose states match the view is used. In this file, state_selected="false" matches every unselected view, so the final white item is used only when the view is selected. A catch-all item at the end has no state attributes.

Each item can either use a color literal, or reference a color defined somewhere else.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents