2

我有一个AppBarLayout带有 aToolbar和 a的布局,ViewPager带有 3 个选项卡。每个选项卡都通过Toolbar'sActionMode使用SearchView. 当我们更新我们的应用程序以使用新的Support library 23.0.1(针对 API 23,并使用构建工具 23.0.1)退出搜索模式时,应用程序会在以下堆栈中崩溃:

FATAL EXCEPTION: main
    Process: com.package.name, PID: 3021
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
            at android.view.ViewGroup.addViewInner(ViewGroup.java:3937)
            at android.view.ViewGroup.addView(ViewGroup.java:3787)
            at android.view.ViewGroup.addView(ViewGroup.java:3728)
            at android.view.ViewGroup.addView(ViewGroup.java:3701)
            at android.support.v7.widget.Toolbar.addChildrenForExpandedActionView(Toolbar.java:1809)
            at android.support.v7.widget.Toolbar$ExpandedActionViewMenuPresenter.collapseItemActionView(Toolbar.java:2048)
            at android.support.v7.internal.view.menu.MenuBuilder.collapseItemActionView(MenuBuilder.java:1345)
            at android.support.v7.internal.view.menu.MenuItemImpl.collapseActionView(MenuItemImpl.java:705)
            at android.support.v7.widget.Toolbar.collapseActionView(Toolbar.java:570)
            at android.support.v7.widget.Toolbar$3.onClick(Toolbar.java:1065)
            at android.view.View.performClick(View.java:4781)
            at android.view.View$PerformClick.run(View.java:19873)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5289)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

恢复Support library 22.0.1一切正常。我看到我的onMenuItemActionCollapse回调被调用,并返回 true,但它似乎在我的代码之外崩溃。

4

1 回答 1

1

问题是由于我们手动从工具栏中添加和删除视图 - 看起来像在支持库 23 中,当搜索视图折叠并且我们对视图的更改与此逻辑冲突时,此特殊按钮被放置在隐藏视图集合中.

解决方案是切换主页按钮的可见性,这解决了崩溃

于 2015-10-13T12:17:49.573 回答