Disable Ripple on ListView

前端 未结 3 1004
醉梦人生
醉梦人生 2021-02-19 09:46

In Android 5.0, my ListView produces a ripple effect when clicking a list item. Is there a way to disable this effect? Looking at the docs, I don\'t see any way (https://develop

相关标签:
3条回答
  • 2021-02-19 10:35

    Try:

    <ListView
    ...
        android:listSelector="@android:color/transparent" />
    

    This will disable any visual effect of touching. Not very good for the user, but might be useful in special circumstances.

    0 讨论(0)
  • 2021-02-19 10:38

    You can remove or replace the list selector using the android:listSelector property. The default list selector under Material is ?android:attr/selectableItemBackground which is a bounded ripple.

    <ListView
        ...
        android:listSelector="@drawable/my_list_selector" />
    

    To completely disable selector, you can use a @null or @android:color/transparent (works better for some Android versions) value as following:

    <ListView
        ...
        android:listSelector="@android:color/transparent" />
    
    0 讨论(0)
  • 2021-02-19 10:45

    Yes, you can create custom list items with their layout, in which you have to change the android:background with a drawable without ripple.

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