Define a color state list
suggest changeColor 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 the order they are defined, and the first item whose specified states match the current state of the view is used. So it’s a good practice to specify a catch-all at the end, without any state selectors specified.
Each item can either use a color literal, or reference a color defined somewhere else.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents