Note that there are some explanatory texts on larger screens.

plurals
  1. POListView item background via custom selector
    primarykey
    data
    text
    <p>Is it possible to apply a custom background to each Listview item via the list selector?</p> <p>The default selector specifies <code>@android:color/transparent</code> for the <code>state_focused="false"</code> case, but changing this to some custom drawable doesn't affect items that aren't selected. Romain Guy seems to suggest <a href="https://stackoverflow.com/questions/2217753/changing-background-color-of-listview-items-on-android/2218270#2218270">in this answer</a> that this is possible.</p> <p>I'm currently achieving the same affect by using a custom background on each view and hiding it when the item is selected/focused/whatever so the selector is shown, but it'd be more elegant to have this all defined in one place.</p> <p>For reference, this is the selector I'm using to try and get this working:</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_focused="false" android:drawable="@drawable/list_item_gradient" /&gt; &lt;!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. --&gt; &lt;item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" /&gt; &lt;item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_background_disabled" /&gt; &lt;item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" /&gt; &lt;item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" /&gt; &lt;item android:state_focused="true" android:drawable="@drawable/list_selector_background_focus" /&gt; &lt;/selector&gt; </code></pre> <p>And this is how I'm setting the selector:</p> <pre><code>&lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:listSelector="@drawable/list_selector_background" /&gt; </code></pre> <p>Thanks in advance for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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