Default selector for selected view

I think this question says it all: is there a default selector from @android/drawablethat I can set as the 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 my own drawings. Is there a default selector for this? Or can I access the default drawings for this so that I can use them in my selector?

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

+4
source share
2 answers

at your option:

<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>
+2

(: attr/selectableItemBackground) : state_selected .

0

Source: https://habr.com/ru/post/1529610/


All Articles