9

Ich versuche Ripple Effekt zu RecyclerView 's Artikel hinzuzufügen. Ich habe online nachgesehen, konnte aber nicht finden, was ich brauche. Ich habe versucht, android:background Attribut auf die RecyclerView selbst und setzen Sie sich auf "?android:selectableItemBackground" aber es hat nicht funktioniert .:Recyclerview item click ripple effect

My Parent Layout ist wie diese

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/dailyTaskList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:focusable="true" 
     android:scrollbars="vertical" /> 
</LinearLayout> 

und Adapter Vorlage

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <TextView 
       android:id="@+id/txtTitle" 
       style="@style/kaho_panel_sub_heading_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/txtDate" 
       style="@style/kaho_content_small_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

    </LinearLayout> 
</LinearLayout> 
in unten

Bitte geben Sie mir die Lösung

+0

Welchem ​​Elternteil Sie versucht android ': background = "android: attr/selectableItemBackground"'? –

Antwort

27

die android:background="?attr/selectableItemBackground" nach oben meisten Eltern Ihres Artikels Layout Hinzufügen sollte es tun. In einigen Fällen fehlt jedoch immer noch die Animation, die android:clickable="true" tut es.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/selectableItemBackground" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="5dp"> 

     <TextView 
      android:id="@+id/txtTitle" 
      style="@style/kaho_panel_sub_heading_textview_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/txtDate" 
      style="@style/kaho_content_small_textview_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
</LinearLayout> 
1

In Ihrem RecyclerView Item Parent, fügen Sie

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

wie unten:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?android:attr/selectableItemBackground" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <TextView 
       android:id="@+id/txtTitle" 
       style="@style/kaho_panel_sub_heading_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/txtDate" 
       style="@style/kaho_content_small_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 


    </LinearLayout> 

</LinearLayout>