0

I want to customize long press color and animation when pressing on listview item in AppCompat theme. I`m using custom selector.

Here is list_selector_background_transition:

 <?xml version="1.0" encoding="utf-8"?>
    <transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/list_selector_background_pressed"  />
    <item android:drawable="@drawable/list_selector_background_longpress"  />
    </transition>

When press its working, but not when long pressing.

    <?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:endColor="@color/primary"
                android:startColor="@color/accent"
                android:angle="270" />
        </shape>
    </item>
</selector>

What should be done?

EDIT. item_selector.xml

  <item android:state_window_focused="false" android:drawable="@android:color/transparent" />

<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true"  android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"  android:drawable="@drawable/list_selector_background_focus" />
saintPeter
  • 203
  • 4
  • 14
  • So where did you use your `list_selector_background_transition`? – tachyonflux Jul 24 '15 at 20:30
  • in the item_selector, which is a background in row layout. – saintPeter Jul 24 '15 at 20:35
  • so what's all that gradient stuff then? – tachyonflux Jul 24 '15 at 20:39
  • What are the color values for pressed and longpress? – tachyonflux Jul 24 '15 at 20:40
  • I was trying to repeat that glowing effect from light blue to dark blue, just change the colors. What I`m doing wrong? – saintPeter Jul 24 '15 at 20:50
  • Long press is working, colors dont work as was in default. I refer to this question http://stackoverflow.com/questions/6513301/android-how-to-achieve-the-glow-effect-when-long-pressing-a-list-item – saintPeter Jul 24 '15 at 21:32
  • I'm voting to close this because the problem is unclear. You've basically copied the default list selector from the SDK, so we know that it is valid. Please create an [MCVE](http://stackoverflow.com/help/mcve) and clearly demonstrate what is not working. – tachyonflux Jul 24 '15 at 22:06

2 Answers2

0

Perhaps this will help you.

I'm guessing you need to take in mind the :state focused tag

<item android:state_focused="true"/>
Community
  • 1
  • 1
mariuss
  • 1,177
  • 2
  • 14
  • 30
0

I think your problem is that you have created a list selector and you are using it as a background. The list selector will take precedence over the background. You should be setting it as the listSelector on your ListView:

<ListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:listSelector="@drawable/item_selector" />
tachyonflux
  • 20,103
  • 7
  • 48
  • 67
  • This help to move further in someway, but it is not what I was asking for. How to alter long press animation colors for AppCompat – saintPeter Jul 24 '15 at 21:17
  • What exactly is your problem? You were saying the long press wasn't working and now you're talking about color customization? – tachyonflux Jul 24 '15 at 21:29
  • Long press is working, colors dont work as was in default. I refer to this question http://stackoverflow.com/questions/6513301/android-how-to-achieve-the-glow-effect-when-long-pressing-a-list-item – saintPeter Jul 24 '15 at 21:32
  • So you're saying you have the exact same behavior as when you didn't have the selector? – tachyonflux Jul 24 '15 at 21:40
  • Exact the same, yes. No animation. – saintPeter Jul 24 '15 at 21:55