且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Google的新NavigationView中将MenuItem添加到SubMenu?

更新时间:2023-12-02 23:27:40

因此,显然,目前唯一的解决方案是使用反射来调用菜单上的notifyDataSetChanged():

So apparently, the only solution right now is to use reflection to call notifyDataSetChanged() on the menu:

    for (int j = 0, count = mNavigationView.getChildCount(); j < count; j++) {
      final View child = mNavigationView.getChildAt(j);
      if (child != null && child instanceof ListView) {
        final ListView menuView = (ListView) child;
        final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
        final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
        wrapped.notifyDataSetChanged();
      }
     }

这将使用您的新项目更新菜单.

This will update the menu with your new items.