问题
I am using NavigationView to display menu.xml data to my NavigationDrawer. It had two groups of checkable items. The first group could have any number of items checked at the same time, the second one could have only one checked.
Support library versions used:
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.0'
xml code used for NavigationView
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="all" android:id="@+id/navgroup_layers" android:menuCategory="container">
<item
android:id="@+id/nav_traffic"
android:checked="true"
android:icon="@drawable/ic_traffic_light"
android:title="@string/Traffic"/>
<item
android:id="@+id/nav_text"
android:checked="true"
android:icon="@drawable/ic_tooltip_text"
android:title="@string/text_labels"/>
</group>
<group android:id="@+id/navgroup_cities"
android:checkableBehavior="single"
android:menuCategory="container"
>
<item
android:id="@+id/nav_berlin"
android:checked="true"
android:icon="@drawable/ic_traffic_light"
android:title="@string/berlin"/>
<item
android:id="@+id/nav_prague"
android:icon="@drawable/ic_subway"
android:checked="false"
android:title="@string/prague"/>
<item
android:id="@+id/nav_paris"
android:checked="false"
android:icon="@drawable/ic_tooltip_text"
android:title="@string/paris"/>
</group>
After I upgraded the libraries to the newest:
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
The checkable behavior changed. Now, when I click on the same item multiple times, it checks and unchecks itself, but when I select a different item, everything gets unchecked and only after another click on the same item, it gets checked. After looking at the source code of the two versions, I could not realize what the problem was. It looks a bit like this chackable behavior attribute is not considered at all in the new version. A bug of the lib or the whole implementation should be suddenly done differently?
回答1:
Version 23 of NavigationView
did entirely change the structure of how the menu is built - it is now based upon RecyclerView as mentioned in the comments of the release Google+ post.
From the NavigationMenuPresenter's Adapter source code (which controls how menu items are displayed and stored), it appears only a single checked item is saved and checking one item does uncheck other checked items.
This would require a new bug report to be filed to get NavigationView
to take into account the checkableBehavior
field.
来源:https://stackoverflow.com/questions/33551592/multiple-checkable-groups-in-navigationdrawer-stopped-working-after-upgrading-su