简体   繁体   English

更改/删除android中底栏的项目

[英]Changing/removing items of Bottom bar in android

I have an activity with a BottomNavigationView , I need to switch items (remove old and add new ones) of my bottomNavigationView when a button is clicked. 我有一个带有BottomNavigationView的活动,我需要在单击按钮时切换我的bottomNavigationView的项目(删除旧的并添加新项目)。 I tried all these options but none of them is working: 我尝试了所有这些选项,但它们都没有工作:

 bottomNavigationView.getMenu().clear();
   bottomNavigationView.getMenu().getItem(0).setVisible(false);
   bottomNavigationView.getMenu().removeItem(0);       bottomNavigationView.removeViewInLayout(bottomNavigationView.findViewById(R.id.explore_item));

I tried using the roughike bottom bar and could find a way to switch bottom bar items with a click. 我尝试使用粗糙的底栏 ,可以找到一种方法来点击切换底部条形项目。

I ended up implementing the worst solution : adding two BottomNavigationViews and switching their visibilty ! 我最终实现了最糟糕的解决方案:添加两个BottomNavigationViews并切换它们的可见性! The problem is I need to switch bottom bar items more than once, and I cant keep adding bottomNavViews to my ui ! 问题是我需要不止一次切换底部条形项目,我不能继续向我的ui添加bottomNavViews!

Any help with switching bottom bar items on a button click would appreciated. 任何有关按钮点击切换底栏项目的帮助将不胜感激。 Thanks. 谢谢。

我找到的唯一解决方案是使用

bottomNavigationView.getMenu().removeItem(R.id.menu_item);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM