Android: How to achieve the glow effect when long-pressing a list item?

后端 未结 1 364
误落风尘
误落风尘 2020-12-08 17:30

With the default selector, long-pressing a list item causes its background to transition between two colors.

Replacing the selector with the one below removes the ef

相关标签:
1条回答
  • 2020-12-08 17:48

    Here is the code from list_selector_background :

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:state_window_focused="false" android:drawable="@android:color/transparent" />
            <!--
                    Even though these two point to the same resource, have two states so
                    the drawable will invalidate itself when coming out of pressed state.
            -->
            <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" />
    </selector>
    

    Found on the web.

    And it uses this transition for long press clicks :

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

    Found on the web too .

    There is no animation for that. And remember to keep you states in the same order, or at least think about it if you swap them, order is important.

    Personnally, I like when things behave in a standard way, so I would just let the standard list selector.

    Regards, Stéphane

    0 讨论(0)
提交回复
热议问题