Recyclerview 點擊效果,可使用

第一步: 新建drawble recycler_touch_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white_fa" android:state_pressed="true"/>
    <item android:drawable="@color/white_fa" android:state_focused="true"/>
    <item android:drawable="@color/white"/>
</selector>
#FAFAFA   #FFFFFF

第二步:新建drawble-21 recycler_touch_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="@color/gray_d7"
    tools:targetApi="lollipop">
    <item android:drawable="@color/white" />
</ripple>
#D7D7D7

第三步: 設置你想要的控件做爲背景

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:background="@drawable/recycler_touch_bg"
   >
    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="您好,我是一條標題"
        android:textColor="@color/yellow_e8"
        android:textSize="@dimen/sp_21" />

</LinearLayout>

這一步有個重要的地方,若是想要在五大布局中設置點擊效果, android:clickable=「true」,記得加上要否則會點擊無效。android

就這麼簡單,對了,若是有好用的圓形點擊效果,請評論一下,我會聯繫你,感謝web