Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By default, <code>ListView</code> has a <code>Selector</code> that will play a <code>TransitionDrawable</code> when you longpress a list item. However, if your list item view has a solid background, then you won't be able to see the selector's longpress animation (or on any other states) , because it's covered up by the list item's background.</p> <p>If you want to see the selector's longpress animation/selected/pressed state, then the list item's has to have a transparent background when the item is selected/pressed/longpressed. You can do it by using a <a href="http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html">StateListDrawable</a> as your item's background instead of a solid color.</p> <p>Here is a sample of <a href="http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html">StateListDrawable</a> for that purpose:</p> <pre><code>public class ColorfulListItemDrawable extends StateListDrawable { private final PaintDrawable mColor; public ColorfulListItemDrawable(int color) { mColor = new PaintDrawable(color); initialize(); } private void initialize() { Drawable color = mColor; Drawable selected = new ColorDrawable(Color.TRANSPARENT); addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled, android.R.attr.state_window_focused}, selected); addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled, android.R.attr.state_window_focused,android.R.attr.state_selected}, selected); addState(new int[] {android.R.attr.state_enabled,android.R.attr.state_window_focused, android.R.attr.state_selected}, selected); addState(new int[] {}, color); } public void setColor(int color) { mColor.getPaint().setColor(color); mColor.invalidateSelf(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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