Reputation: 2243
I am trying to add Ripple Effect to RecyclerView's item. I had a look online, but could not find what I need. I have tried android:background attribute to the RecyclerView itself and set it to "?android:selectableItemBackground" but it did not work.:
adapter template is shown in below
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/u_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="left"
android:maxLines="1"
android:paddingLeft="@dimen/u_common_text_size"
android:paddingRight="@dimen/u_common_text_size"
android:singleLine="true"
android:text="Item"
android:textColor="#808080"
android:textSize="@dimen/u_common_text_size" />
<TextView
android:id="@+id/u_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="5dip"
android:gravity="left"
android:maxLines="1"
android:paddingLeft="@dimen/u_common_text_size"
android:paddingRight="@dimen/u_common_text_size"
android:singleLine="true"
android:text="Item"
android:textColor="@android:color/black"
android:textSize="@dimen/u_common_text_size" />
<View
android:id="@+id/bottomline"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e6e6e6"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
Upvotes: 2
Views: 1579
Reputation: 1241
if you use ConstraintLayout, try this
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
Upvotes: 2
Reputation: 173
Looking to the LinearLayout parent view background, I saw that the background attribute is not correct (you forgot the android between the question mark and the :attr).
android:background="?android:attr/selectableItemBackground"
Upvotes: 1