Android Cannot resolve symbol '?attr/selectableItemBackground'

Viewed 18702
<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/card_outer_padding"
    android:layout_marginTop="@dimen/card_outer_padding"
    android:layout_marginRight="@dimen/card_outer_padding"
    android:layout_marginBottom='@{model.cardBottomMargin}'
    android:foreground="?attr/selectableItemBackground"
    android:onClick="@{model::onCardClick}"
    app:cardElevation="2dp"
    app:cardCornerRadius="2dp"
    app:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>

I got this error message

Cannot resolve symbol ?attr/selectableItemBackground Validates resource references inside Android XML files.

<TextView
    android:id="@+id/country_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="40dp"
    android:text="@{model.name}"
    style="@style/TextAppearance.AppCompat.Headline"
    tools:text="Country"/>

And, I got a similar error for the above as well

Cannot resolve symbol '@style/TextAppearance.AppCompat.Headline'
Validates resource references inside Android XML files.

Any pointer would be great! Thank you! It seems to be related to this thread but no solution was provided:

10 Answers

I have solved by,

  • Deleting the .idea folder in project explorer.
  • Invalidate Caches/Restart
  • Refresh Project Gradle

This is what solved to me:

  1. Close Android Studio
  2. Delete .idea directory in the root project directory

enter image description here

  1. Reimport the project

enter image description here

I updated my gradle version to 4.10.1 and fix and reimport repaired it. There were no libraries folder under .idea before.

If you use applicationContext for LayoutInflater, then replace it to normal context. It works for me.

Related