gpt4 book ai didi

android - selectableItemBackground 作为图层列表中的项目

转载 作者:IT老高 更新时间:2023-10-28 22:14:45 27 4
gpt4 key购买 nike

我从 Google IO Schedule 应用源 (https://github.com/google/iosched) 复制了一个文件,即

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 中当前选定的项目。我的问题是,当我启动我的应用程序时,它会引发异常。

这是我认为的重要线路。

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"/>

我不知道是什么问题,我是从源代码复制过来的,没有调整它。它在他们的应用中运行良好。

我尝试将 ?android:selectableItemBackground 更改为 ?attr/selectableItemBackground,但它给了我同样的异常。我似乎找不到任何其他建议的解决方案。

如果有人知道这是什么原因,请帮助我。

最佳答案

它可以工作,但来自 api v21。因此,您可以继续在具有 Android Lollipop 及更新版本的设备上使用它。如果您想支持旧系统版本,您可以将此 xml 放入 drawable-v21 文件夹,并在 drawable 文件夹中准备新的 xml 同名。例如:

drawable/selected_navdrawer_item_background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#12000000" />
</shape>

Google IO 应用做同样的事情: here is file from drawable folderhere is file from drawable-v21 folder

关于android - selectableItemBackground 作为图层列表中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28432686/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com