android - RecyclerView 项中的背景选择器

标签 android selector android-recyclerview

我正在使用 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的所有元素中设置clickablefocusablefocusableInTouchModetrue > “列表”。

关于android - RecyclerView 项中的背景选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392722/

相关文章:

java - Twisted 吞吐量限制降低

android - Recyclerview网格布局项目剪切问题

android - 如何使座位布局像redbus?

android - 没有为 android ant 脚本设置 "includeAntRuntime"?

java - 在 android 中实现 authorize.net

jquery - 表单输入的样式祖先元素:focus (jQuery)

android - android 选择器的按下状态不起作用

android - RecyclerView ScrollY 始终为 0

android - 无法将项目导入android studio

c# - Xamarin Android应用程序未达到断点