【发布时间】:2014-10-13 02:28:10
【问题描述】:
我正在使用RecyclerView,如下所示:
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="320dp"
android:layout_height="match_parent"/>
还有我的列表项:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_medium_high">
<com.basf.suvinil.crie.ui.common.widget.CircleView
android:id="@+id/circle"
android:layout_width="22dp"
android:layout_height="22dp"/>
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="57.5dp"/>
</LinearLayout>
详细看这部分android:background="@drawable/selector_medium_high"这是一个普通的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/background_high" android:state_activated="true"/>
<item android:drawable="@color/background_high" android:state_pressed="true"/>
<item android:drawable="@color/background_high" android:state_checked="true"/>
<item android:drawable="@color/background_high" android:state_focused="true"/>
<item android:drawable="@color/background_medium"/>
</selector>
但是当我运行这段代码时,当我触摸行时,背景颜色没有变化......
【问题讨论】:
-
不幸的是,使用可聚焦视图不是跟踪选择的好方法。检查我的答案以获得完整的解决方案。
标签: android selector android-recyclerview