0

I have a Recycler view and their items should be clickable. I want that all line do apply the ?selectableItemBackground effect but this does not occurs. The imageview is occupying all the item layout as an background. Why the selectable effect doesn't working as well?

this is my xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="?listPreferredItemHeightLarge"
    android:background="?selectableItemBackground"
    android:descendantFocusability="blocksDescendants">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true">
        <ImageView
            android:id="@+id/background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/app_name"
            android:src="@drawable/holder"
            android:scaleType="centerCrop"
            android:focusableInTouchMode="false"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/black"
            android:alpha="0.3" />
    </FrameLayout>

    <br.com.lexsis.pizzahut.presentation.widgets.CustomFontTextView
        android:id="@+id/group_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="@android:color/transparent"
        style="@style/TextView.EMenu" />

</RelativeLayout>
Lal
  • 14,726
  • 4
  • 45
  • 70
pablobaldez
  • 924
  • 14
  • 22

1 Answers1

-1

You can add another RelativeLayout and add android:background="?attr/selectableItemBackground" to it:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="?listPreferredItemHeightLarge"
    android:background="?selectableItemBackground"
    android:descendantFocusability="blocksDescendants">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true">

            <ImageView
                android:id="@+id/background"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/app_name"
                android:src="@drawable/holder"
                android:scaleType="centerCrop"
                android:focusableInTouchMode="false"/>

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/black"
                android:alpha="0.3" />

        </FrameLayout>

        <br.com.lexsis.pizzahut.presentation.widgets.CustomFontTextView
            android:id="@+id/group_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:background="@android:color/transparent"
            style="@style/TextView.EMenu" />

    </RelativeLayout>

</RelativeLayout>

Setting it to the root layout never worked for me.

Lennoard Silva
  • 767
  • 1
  • 8
  • 17