Question

I think the question says it all: Is there a default Selector from @android/drawable which I can set as background for my view if I call:

view.setSelected(true);

I want to use the default colors from android but in a custom Selector I can only add own drawables. Is there a default selector for this? Or can I access the default drawables for that so I can use them in my own Selector?

I tried with android:background="?android:attr/selectableItemBackground" but If I call view.setSelected(true); nothing happened.

Was it helpful?

Solution

in your drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
      android:state_selected="true"> <!-- selected -->
    <shape
        android:shape="rectangle">
      <solid
          android:color="#444444"/>
    </shape>
  </item>
  <item> <!-- not selected -->
    <shape
        android:shape="rectangle">
      <solid
          android:color="#888888"/>
    </shape>
  </item>
</selector>

OTHER TIPS

In the above drawable(android:attr/selectableItemBackground) there is no drawable specified for the state android:state_selected.

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