在XML可绘制对象中使用主题引用需要API级别21 [英] Using theme references in XML drawables requires API level 21
本文介绍了在XML可绘制对象中使用主题引用需要API级别21的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使以下代码与较低的API级别兼容:
Is there a way to make 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>
部分: android:drawable =?android:attr / selectableItemBackground
产生以下消息:
在XML可绘制对象中使用主题引用需要API级别21(当前最小值为15)
Using theme references in XML drawables requires API level 21 (current min is 15)
推荐答案
在values文件夹下创建一个attars.xml文件。
Create an attars.xml file under the values folder.
在attars.xml文件中,为selectableItemBackground创建一个项目:
In the attars.xml file, create an item for selectableItemBackground:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="selectableItemBackground" format="reference" />
</resources>
在styles.xml中使用可绘制对象定义此属性:
In your styles.xml define this attribute with your drawable:
<item name="selectableItemBackground">@drawable/yourDrawable</item>
然后在可绘制文件中,引用属性:
And then in your drawable file, reference the attribute:
<item android:drawable="?attr/selectableItemBackground"/>
这篇关于在XML可绘制对象中使用主题引用需要API级别21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文