0

I'm using CardView in my project and I'm getting an error on older devices:

 E  android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.widget.CardView
                        E      at android.view.LayoutInflater.createView(LayoutInflater.java:518)
                        E      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
                        E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
                        E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
                        E      at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
                        E      at android.view.LayoutInflater.inflate(LayoutInflater.java:320)

Seems similar to a few questions on SO such as this one

My problem is that the solution for that questions feels very hacky and that's understandable as the answer was given last year when Lollipop just entered the public preview. Have things changed since? How do I get the resources?

I've tried a few things such as importing .aar as a module but nothing seems to work. I've followed the official documentation on how to add support libraries (https://developer.android.com/tools/support-library/setup.html#libs-with-res) but that didn't work. Also according to that link - there doesn't seem to be any difference between adding libraries with and without resources for Android Studio?

My app build.gradle includes the following dependencies:

compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'

CardView layout is used here

    <android.support.v7.widget.CardView
        xmlns:card="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:foreground="?android:attr/selectableItemBackground"
        card:cardCornerRadius="6dp"
        card:cardUseCompatPadding="true"
        tools:ignore="NewApi">

EDIT: the problem noticed on Samsung S2 2.3 - API 19+ works fine

Community
  • 1
  • 1
vkislicins
  • 3,331
  • 3
  • 32
  • 62

1 Answers1

3

?android:attr/selectableItemBackground is platform related, use it without android: prefix to refer to AppCompat's attribute.

GPack
  • 2,494
  • 4
  • 19
  • 50
  • amazing, thank you so much!! do you have any reference to this in documentation? I obviously missed that part... – vkislicins Apr 29 '15 at 17:24
  • http://developer.android.com/reference/android/R.attr.html#selectableItemBackground – GPack Apr 29 '15 at 17:36