Maybe this question has been asked before, but I couldn't find a precise answer. I have implemented the RecyclerView
widget as a list in my L test application and I want to get the 'material effect' when you click on an item form the list. I implemented an onClickListener
in my ViewHolder
creation and set the attribute
android:background="?android:attr/selectableItemBackground"
as a background to my list item layout (to the parent).
But none of this worked. When I click on the items NOTHING happens'. There is no effect, holo, material, none... Please point out if I am doing something wrong here... Thx
Sandra's answer didn't work for me. I needed one more property in my list item layout:
android:clickable="true" android:focusable="true" android:background="?android:attr/selectableItemBackground"
Note: if you get an error when pasting in the last line, then your android app is set on version 10 or below. Just right click on the error in Android Studio and set it so it will create a v11 version of your layout as well. Then, in the original layout, make sure to delete
android:background="?android:attr/selectableItemBackground"`
This is because the animation isn't supported in v10 versions of android or lower. With these two layout files set up, the animation will correctly show in v11+ versions of Android and of course it won't be shown in lower versions.
(or just increase the minSdkVersion version of your app to higher than 10)
I made a silly mistake and did not put
android:clickable="true" android:focusable="true"
to my list item layout. I think this was not required pre L, but it doesn't matter because that was the problem in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With