如何在BottomNavigationView中动态隐藏菜单项? [英] How to dynamically hide a menu item in BottomNavigationView?

查看:921
本文介绍了如何在BottomNavigationView中动态隐藏菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据某些条件动态隐藏BottomNavigationView的菜单项.我尝试了以下操作,但无法正常工作.

I want to hide a menu item of BottomNavigationView dynamically based on some conditions. I tried the following but it is not working.

mBottomNavigationView.getMenu()
            .findItem(R.id.item_name)
            .setVisible(false);

mBottomNavigationView.invalidate();

推荐答案

mBottomNavigationView.getMenu().removeItem(R.id.item_name);

removeItem 可以解决问题.不确定为什么setVisible方法不起作用.

removeItem does the trick. Not sure why setVisible method is not working.

这篇关于如何在BottomNavigationView中动态隐藏菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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