android - 在 android 中对 RecyclerView 的项目启用按下效果

标签 android android-recyclerview

我有带有数据列表的 RecyclerView:

<android.support.v7.widget.RecyclerView
        android:id="@+id/categoriesList"
        android:layout_width="368dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:clickable="true"
        android:focusable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:background="?android:selectableItemBackground"/>

当我点击此列表中的任何项目时,我会等待按下效果。我没有点击处理程序,但在标准 ListView 中,对元素的任何点击都是可见的。而且我看起来没什么 react

我需要下一个:

enter image description here

最佳答案

您需要将这些行添加到单行布局而不是 recyclerview 标签。

android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:background="?android:selectableItemBackground"

关于android - 在 android 中对 RecyclerView 的项目启用按下效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47344795/

相关文章:

android - Otto 在 vi​​ewpager 中抛出 "Object already registered"onResume

android - 我有一个带有回收器 View 适配器类的 Activity ,当在适配器类中单击按钮时我想刷新主要 Activity

android - RecyclerView 的可扩展 TextView

java - 如何从所有用户的 FirebaseRecyclerAdapter 中隐藏当前用户?

android - 在 KitKat 4.4.4 API 19 上使用改造上传图像时应用程序崩溃

android - 如何停止动画(cancel() 不起作用)

java - JarJar'ed artefact 和 Maven 部署过程

java - Glide 用加载的图像部分覆盖屏幕

android - RecyclerView 在聊天屏幕中滚动到 notifyDataSetChanged 顶部

ViewPager 中的 Android ListFragment 使用上下文菜单