Issue
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>
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
Line # 22 is this one
<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.
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.
Solution
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 app does the same thing: here is file from drawable folder and here is file from drawable-v21 folder
Answered By - lukjar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.