Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've been frustrated by this myself and finally solved it. As Romain Guy hinted to, there's another state, <code>"android:state_selected"</code>, that you must use. Use a state drawable for the background of your list item, and use a different state drawable for <code>listSelector</code> of your list:</p> <p>list_row_layout.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:background="@drawable/listitem_background" &gt; ... &lt;/LinearLayout&gt; </code></pre> <p>listitem_background.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_selected="true" android:drawable="@color/android:transparent" /&gt; &lt;item android:drawable="@drawable/listitem_normal" /&gt; &lt;/selector&gt; </code></pre> <p>layout.xml that includes the ListView:</p> <pre><code>... &lt;ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:listSelector="@drawable/listitem_selector" /&gt; ... </code></pre> <p>listitem_selector.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:drawable="@drawable/listitem_pressed" /&gt; &lt;item android:state_focused="true" android:drawable="@drawable/listitem_selected" /&gt; &lt;/selector&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload