No ripple effect on recycleview touch event
Asked Answered
F

1

1

I have implemented navigation drawer using RecycleView, but when I click on items, no ripple effect shown. My device is running API 22.

fragment_navigation.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white">


<RelativeLayout
        android:id="@+id/nav_header_container"
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:layout_alignParentTop="true"
        android:background="@color/colorPrimary">

    <ImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/ic_profile"
            android:scaleType="fitCenter"
            android:layout_centerInParent="true" />

</RelativeLayout>


<android.support.v7.widget.RecyclerView
        android:id="@+id/drawerList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/nav_header_container"
        android:layout_marginTop="15dp" />


        </RelativeLayout>

and my rows are:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true">
<ImageView android:layout_width="wrap_content"    android:layout_height="wrap_content"
           android:scaleType="fitCenter"
        android:src="@android:drawable/ic_input_get" android:id="@+id/imageView"/>
<TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="30dp"
        android:paddingTop="10dp"
        android:text="asa"
        android:paddingBottom="10dp"
        android:textSize="15dp"
        android:textStyle="bold"
        android:layout_alignParentTop="true" android:layout_toRightOf="@+id/imageView"
        android:layout_toEndOf="@+id/imageView"/>

    </RelativeLayout>

What is the problem and how can I resolve this?

Feuilleton answered 21/6, 2015 at 11:6 Comment(5)
what's your device's API version?Charleycharlie
So did you apply material theme for you layout/item elements? developer.android.com/training/material/theme.htmlCharleycharlie
If you are sure that you are using a Material theme, or an appCompat theme and it still doesn't work try adding this line to the root of your row's layout android:background="?android:selectableItemBackground"Amphigory
when i click on items there is no select effect, so theme not a answerFeuilleton
@user3106978, thanks your suggestion workedFeuilleton
S
3

Try this as your Row layout

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?android:attr/selectableItemBackground"
                android:focusable="true"
                android:clickable="true">

 <ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    android:src="@android:drawable/ic_input_get"
    android:id="@+id/imageView"/>

 <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="30dp"
            android:paddingTop="10dp"
            android:text="asa"
            android:paddingBottom="10dp"
            android:textSize="15dp"
            android:textStyle="bold"
            android:layout_toRightOf="@+id/imageView"
            android:layout_alignParentTop="true"  
            android:layout_toEndOf="@+id/imageView"/>

        </RelativeLayout>
Saga answered 21/6, 2015 at 12:15 Comment(2)
Not sure why more people did not find this useful, it really saved a couple of hours.Twinkling
so many people are posting other ways of selectableItemBackground but this is the only one that worked for me!Boliviano

© 2022 - 2024 — McMap. All rights reserved.