升级支持设计库后,NavigationDrawer中的多个可检查组停止工作 [英] Multiple checkable groups in NavigationDrawer stopped working after upgrading support design library

查看:61
本文介绍了升级支持设计库后,NavigationDrawer中的多个可检查组停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NavigationView在我的NavigationDrawer中显示menu.xml数据.它有两组可检查的物品.第一组可以同时检查任意数量的项目,第二组可以只检查一个项目.

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.

使用的支持库版本:

compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.0'

用于NavigationView的xml代码

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'

可检查的行为已更改.现在,当我多次单击同一项目时,它会自行检查并取消选中,但是当我选择其他项目时,所有内容都将变为未选中状态,只有在再次单击同一项目后,它才会被选中. 在查看两个版本的源代码之后,我无法意识到问题出在哪里.看起来有点像在新版本中根本没有考虑此可hackable行为属性. lib的错误或整个实现的错误应该突然改变吗?

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?

推荐答案

NavigationView的版本23完全改变了菜单构建方式的结构-现在它基于

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.

这将需要新的错误报告以便获得NavigationView并将checkableBehavior字段考虑在内.

This would require a new bug report to be filed to get NavigationView to take into account the checkableBehavior field.

这篇关于升级支持设计库后,NavigationDrawer中的多个可检查组停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆