2017-11-17 7 views
1

にRecyclerViewの項目のプレス効果を有効にします私はデータのリストをRecyclerViewを持っている:私はこのリストの任意の項目をタップするとはアンドロイド

<android.support.v7.widget.RecyclerView 
     android:id="@+id/categoriesList" 
     android:layout_width="368dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:clickable="true" 
     android:focusable="true" 
     android:foreground="?android:attr/selectableItemBackground" 
     android:background="?android:selectableItemBackground"/> 

、私は押して効果を待ちます。クリックハンドラはありませんが、標準のListViewでは、要素のクリックがすべて表示されます。私は次の必要

を反応させる何もないように、私は見て:

enter image description here

+0

あなたはアイテムをタップすると仰角で試すことができます –

答えて

1

これらの行は、recyclerviewタグの代わりに1行レイアウトに追加する必要があります。

android:clickable="true" 
android:focusable="true" 
android:foreground="?android:attr/selectableItemBackground" 
android:background="?android:selectableItemBackground" 
0

これはあなたの答えです:あなたはそれをカスタマイズして、あなたのあたりとして使用することができますHow can I give an imageview click effect like a button on Android?

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="true" 
     android:drawable="@drawable/img_down" /> 
    <item android:state_selected="false" 
     android:drawable="@drawable/img_up" /> 
</selector> 

色の選択。