我正在使用 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>
但是当我运行这段代码时,当我触摸行时,背景颜色没有变化......
最佳答案
在RecyclerView
的所有元素中设置clickable
、focusable
、focusableInTouchMode
为true
> “列表”。
关于android - RecyclerView 项中的背景选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392722/