How to highlight a pressed cardView on IceCreamSandwich (Android 4.0.4)

626 views Asked by At

This is my CardView layout :

<it.gmariotti.cardslib.library.view.CardView
        xmlns:card="http://schemas.android.com/apk/res-auto"
        android:id="@+id/list_cardId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp"
        card:card_layout_resourceID="@layout/cardview_history"
        style="@style/list_card.base"/>

Based on that layout, my CardViews layout is correctly displayed but don't get highlighted when pressed.

On IceCreamSandwich (API 15 : 4.0.4) and unlike later OS versions, if we click on a CardView, it won't be highlighted. So I tried to explicitly add a background card_selector to my CardView.

android:background="@drawable/card_selector"

I'm using the default existing drawable available in the cardslib resource (card_selector.xml) :

<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:exitFadeDuration="@android:integer/config_mediumAnimTime">

    <item android:state_activated="true" android:drawable="@drawable/activated_background_card"/>
    <item android:state_pressed="true" android:drawable="@drawable/pressed_background_card"/>
    <item android:drawable="@drawable/card_background"/>
</selector>

But here is how my CardViews layout become, and as you can see, one of them is pressed but not correctly highlighted.

Is there a solution to make my CardView highlight correctly when pressed?

0

There are 0 answers