Using topic references in XML drawings requires API level 21

Is there a way to make the following code compatible with lower API levels:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="?android:attr/selectableItemBackground"/> <item android:gravity="bottom"> <shape android:shape="rectangle"> <size android:height="1px"/> <solid android:color="#ccc"/> </shape> </item> </layer-list> 

Part: android:drawable="?android:attr/selectableItemBackground" displays this message:

Using topic references in XML drawings requires API level 21 (current minimum is 15)

+5
source share
2 answers

use android:drawable="?attr/selectableItemBackground"

0
source

Create the attars.xml file under the values ​​folder.

In the attars.xml file, create an element for selectableItemBackground:

 <?xml version="1.0" encoding="utf-8"?> <resources> <attr name="selectableItemBackground" format="reference" /> </resources> 

In your styles.xml file, specify this attribute with drawable:

 <item name="selectableItemBackground">@drawable/yourDrawable</item> 

And then in your drawing-capable file, reference the attribute:

 <item android:drawable="?attr/selectableItemBackground"/> 
0
source

Source: https://habr.com/ru/post/1262797/


All Articles