selectableItemBackground作为图层列表中的项目 [英] selectableItemBackground as item in layer-list
问题描述
我已从Google IO Schedule应用程序源( https://github.com/google/iosched ),即
I've copied a file from the Google IO Schedule app source (https://github.com/google/iosched) namely
selected_navdrawer_item_background.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/backgroundColor">
<shape>
<solid android:color="#12000000" />
</shape>
</item>
<item android:drawable="?android:selectableItemBackground"/>
</layer-list>
我想用它在NavigationDrawer中突出显示当前选中的项目.我的问题是,当我启动应用程序时,它会引发异常.
I want to use this to highlight the currently selected item in a NavigationDrawer. My problem is, when I launch my app, it throws an exception.
这是我认为重要的一句话.
This is the important line I think.
caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #22:
<item> tag requires a 'drawable' attribute or child tag defining a drawable
第22行是这个人
<item android:drawable="?android:selectableItemBackground"/>
我不知道问题出在哪里,我从源代码复制了此代码,而没有进行调整.在他们的应用程序中运行正常.
I don't know what the problem is, I copied this over from source without adjusting it. It's working fine in their app.
我试图将?android:selectableItemBackground
更改为?attr/selectableItemBackground
,但这给了我同样的例外.
我似乎找不到其他建议的解决方案.
I tried to change ?android:selectableItemBackground
to ?attr/selectableItemBackground
, but it gives me the same exception.
I can't seem to find any other suggested solutions.
如果有人知道是什么原因造成的,请帮助我.
If anyone knows what's causing this, please help me.
推荐答案
它有效,但可以通过api v21 使用.因此,您可以继续在 Android Lollipop 及更高版本的设备上使用它.如果要支持较旧的系统版本,可以将此xml放入 drawable-v21 文件夹中,并在drawable文件夹中准备相同名称的新xml. 例如:
It works but from api v21. So, you can go ahead and use it on devices with Android Lollipop and newer. If you want support older system versions you can put this xml into drawable-v21 folder and prepare new xml in drawable folder with the same name. For example:
drawable/selected_navdrawer_item_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#12000000" />
</shape>
Google IO应用程序执行相同的操作: 这是可绘制文件夹中的文件, 这是drawable-v21文件夹中的文件
Google IO app does the same thing: here is file from drawable folder and here is file from drawable-v21 folder
这篇关于selectableItemBackground作为图层列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!