RecyclerView Item 中的背景选择器 [英] Background Selector in RecyclerView Item

查看:58
本文介绍了RecyclerView Item 中的背景选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RecyclerView,如下所示:

I'm using the RecyclerView like below:

<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"这是一个普通的选择器:

see in detail this part android:background="@drawable/selector_medium_high" it's a normal selector:

<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>

但是当我运行此代码时,当我触摸该行时,背景颜色没有变化......

but when I run this code, i have no changes in background color when I touch the row....

推荐答案

Set clickable, focusable, focusableInTouchModetrueRecyclerViewlist"的所有元素中.

Set clickable, focusable, focusableInTouchMode to true in all elements of RecyclerView "list".

这篇关于RecyclerView Item 中的背景选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆