Android Cannot resolve symbol '?attr/selectableItemBackground'

Solution 1:

I believe this is a communication problem with the IDE and Android Gradle Plugin. In any case, the only way I've reliably found to resolve this is to delete the problematic libs in the .idea/libraries/ folder.

So, for you, since the lint checks aren't recognizing ?attr/selectableItemBackground

  1. LOCATE the Gradle__com_android_support_xxx.xml files
  2. DELETE those files
  3. SYNC IDE with file system
  4. SYNC project with Gradle files
  5. REBUILD your project

You can sync by clicking on 'File' at the top by the toolbar and selecting "Sync with File System" and then afterwards selecting "Sync project with gradle files".

I've tried other suggested solutions - had the appcompat-v7 dependency in my module build.gradle file & the google() repository as the first line in the project build.gradle dependencies. Nada.

These solutions also haven't helped...

  • Invalidating the caches/restarting didn't work.
  • Cleaning/Rebuilding the project.

Solution 2:

For version Lollipop and higher use this:

android:foreground="?android:attr/selectableItemBackground"

for Pre-Lollipop use this:

android:foreground="?attr/selectableItemBackground"