第一步: 新建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”,记得加上要不然会点击无效。
就这么简单,对了,如果有好用的圆形点击效果,请评论一下,我会联系你,感谢