android - apply selectableItemBackground in xml with support v7

CQM picture CQM · Oct 31, 2013 · Viewed 76.3k times · Source

even with android support v7 included in my application

adding android:background="?android:attr/selectableItemBackground"

makes my IDE, Eclipse throw an error (preventing me from compiling), notifying me that selectableItemBackground is only for min Api 11 and up.

How do I add this attribute to a background in XML?

assume that copying and pasting from a higher library is not a solution

Answer

Vikram picture Vikram · Nov 5, 2013

Since the attribute is defined in a library (support v7), you would use it as a user-defined attribute: i.e without the android: prefix:

android:background="?attr/selectableItemBackground"

The error you see is pointing out that ?android:attr/selectableItemBackground is available for API versions >= 11. True, indeed.