简体   繁体   中英

Android ripple on CardView not triggering onClick

I want to display a ripple effect on my cardview and know it can be done like this:

  android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"

The problem is, my onclicklistener does not recognise the clicks on my card anymore. Without those two attributes it works fine. I also noticed if I remove the clickable attribute only the first card in my list gets the ripple effect and it starts from the middle, not from where I press. The other cards just get a darker background on click. IS there any fix avaliable for this problem?

For mine I only had

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

not

android:clickable="true"

and it worked fine with onclicklistener, from where the user clicked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM