My custom selector like below doesn't work as expected, I don't see the pressed state at all. Any tip? thanks
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
>
<!-- this state button has special design:
+ enabled state has white text on green background
+ disabled state has grey text on greyer background
-->
<item android:state_enabled="true"
android:drawable="@drawable/cb_shape_button_primary"
android:color="@color/white"
/>
<item android:state_pressed="true"
android:drawable="@drawable/cb_shape_button_pressed"
android:color="@color/white"
/>
<item android:state_focused="true"
android:drawable="@drawable/cb_shape_button_pressed"
android:color="@color/white"
/>
<item android:state_enabled="false"
android:drawable="@drawable/cb_shape_button_flat"
android:color="@color/grey_subtext"
/>
</selector>
Try moving state_pressed to top like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
>
<!-- this state button has special design:
+ enabled state has white text on green background
+ disabled state has grey text on greyer background
-->
<item android:state_pressed="true"
android:drawable="@drawable/cb_shape_button_pressed"
android:color="@color/white"
/>
<item android:state_enabled="true"
android:drawable="@drawable/cb_shape_button_primary"
android:color="@color/white"
/>
<item android:state_focused="true"
android:drawable="@drawable/cb_shape_button_pressed"
android:color="@color/white"
/>
<item android:state_enabled="false"
android:drawable="@drawable/cb_shape_button_flat"
android:color="@color/grey_subtext"
/>
Edit:
As @forcewill mentioned, Just to note that the reason behind moving the pressed state to the top has to do with the fact that Android will use the first state that match, in your case the widget is enabled and pressed simultaneous so it was matching the enabled state first.