I try to implement the Material Design's elevation concept to my RecyclerView.
For each item of the RecyclerView I use this
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="0dp"
android:elevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
.../>
<CheckBox
.../>
</RelativeLayout>
</android.support.v7.widget.CardView>
When I select item, I apply programmatically a drawable to the background for effect, and I set the elevation to 8dp as advised by Material Design specifications.
val draw = ResourcesCompat.getDrawable(resources, R.drawable.selected_task, null)
draw?.setColorFilter(task.color.aRGB.toInt(), PorterDuff.Mode.OVERLAY)
view.background = draw
view.elevation = 8F
(I code in Kotlin) The drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="@color/select_border"/>
<solid
android:color="@color/select_fill"/>
</shape>
and the colors values
<color name="select_border">#78000000</color>
<color name="select_fill">#32000000</color>
The problem is when I select one item, the drawable is nicly applied but the shadows are tottaly removed and not amplified ! And if I not set the background with the drawable, it's works well. The shadows are amplified like expected.
What is the problem ?