Can a selector resource use a color defined in a style?

Solution 1:

<item android:state_selected="false"
    android:drawable="?unread_background" />

this above section is wrong.

the drawable only take a reference to a drawable resource. Please see this link. http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Solution 2:

Here is something, that works by me.

attrs.xml:

<attr name="color_selection" format="reference"/>

styles.xml, as child of main theme:

<item name="color_selection">@color/selection_background_inverse</item>

shape_background_selected.xml in drawable folder:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="?attr/color_selection"/>
</shape>

your selector file, in my case: selector_background_recyclerview:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/shape_background_selected" android:state_activated="true" />
    <item android:drawable="@drawable/shape_background_selected" android:state_pressed="true" /> <!-- pressed -->
    <item android:drawable="@color/transparent" /> <!-- default -->
</selector>

finally, in your view's xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:background="@drawable/selector_recyclerview_item_background"../>