listView 添加点击效果

     之前给listView布局文件添加listSelector,然后写一个选择器。

<?xml version="1.0" encoding="utf-8"?>

<selector

  xmlns:android="
http://schemas.android.com/apk/res/android
">

    <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/background_undercard_press" />

    <item android:state_focused="false" android:state_pressed="true" android:drawable="@color/background_undercard_press" />

    <item android:state_focused="true" android:drawable="@color/background_undercard_press" />

    <item android:drawable="@color/transparent" />

</selector>



 <color name="background_undercard">#ffe4e2d7</color>

    <color name="background_undercard_press">#ffe0d7c9</color>

     <color name="transparent">#00000000</color>

发现点击没有效果,

然后在item找到根布局文件然后将该select设置给listView的background。这样点击就有了效果。

   android:background="@drawable/list_selector_transition"

你可能感兴趣的:(listView 添加点击效果)