Adding Ripple Effect to RecyclerView item

前端 未结 6 1838
后悔当初
后悔当初 2020-11-28 02:17

I am trying to add Ripple Effect to RecyclerView\'s item. I had a look online, but could not find what I need. I assume it has to be a custom effect. I have tried android:ba

6条回答
  •  借酒劲吻你
    2020-11-28 02:46

    I figured out. The only thing that I had to do is to add this attribute:

    android:background="?android:attr/selectableItemBackground"
    

    to the root element of the layout that my RecyclerView adapter inflates like that:

    
    
        
    
        
    
    
    

    Result:

    enter image description here

    If you are still not able to see ripple effect, add these lines also to the root element of the layout.

    android:clickable="true"
    android:focusable="true"
    

提交回复
热议问题