在RecyclerView项目背景选择 [英] Background Selector in RecyclerView Item

查看:562
本文介绍了在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>

详细

看这部分安卓背景=@可绘制/ 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>

但是当我运行此code,我在背景颜色没有改变,当我接触的行....

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

推荐答案

在my_list_view的所有元素集点击,可聚焦,focussableInTouchMode为true。

Set clickable, focusable, focussableInTouchMode to true in all elements of "my_list_view".

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

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