Question

<item android:state_enabled="false" android:color="@android:color/bright_foreground_dark_disabled"/>
<item android:color="@android:color/bright_foreground_dark"/>

What is the difference between these two? According to the documentation the color of the first item is used when the state is NOT enabled, and the second is the default one. So, if the item is not enabled, which color is used?

Was it helpful?

Solution

If the item is not enabled the first item is used, as it matches all its state selectors. Selector items are checked from top to bottom, and the first one for which the state matches is used.

OTHER TIPS

false states are intended to be used in combination with other states. For example, you have checkable item, and it can be either disabled or enabled, and you want to have different drawables for each state combination. This can be achieved the following way:

<item android:state_checked="true" android:state_enabled="true" android:drawable="@drawable/drawable1"/>
<item android:state_checked="true" android:state_enabled="false" android:drawable="@drawable/drawable2"/>
<item android:state_checked="false" android:state_enabled="true" android:drawable="@drawable/drawable3"/>
<item android:state_checked="false" android:state_enabled="false" android:drawable="@drawable/drawable4"/>
<item android:drawable="@drawable/drawable0"/>

If you don't need such combinations, there's no need to use state_xxx="false" without other states, though that's not a mistake.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top