I've created bottom bar navigation with menu. I want to remove menu items by checking some conditions, so i want it remove using java code. I have tried it using onCreateOptionsMenu()
, but somehow it did not work. I don't know what am i doing wrong, a little help would be appreciated.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.member_activities);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomViewBar);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
menu = bottomNavigationView.getMenu();
MenuItem menuItem = menu.getItem(0);
menuItem.setChecked(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
menu.removeItem(R.id.district_tab);
return true;
}
bottom_navigation_menu.xml:
<item
android:id="@+id/member_tab"
android:icon="@drawable/ic_person_outline"
android:title="Member"/>
<item
android:id="@+id/club_tab"
android:icon="@drawable/ic_person_outline"
android:title="Club"/>
<item
android:id="@+id/district_tab"
android:icon="@drawable/ic_person_outline"
android:title="District"/>
<item
android:id="@+id/ag_tab"
android:icon="@drawable/ic_person_outline"
android:title="AG"/>
<item
android:id="@+id/dg_tab"
android:icon="@drawable/ic_person_outline"
android:title="DG"/>
onCreateOptionsMenu
its for the menu in the toolbar.
For the menu in your BottomNavigationView you need to use bottomNavigationView.getMenu().removeItem(R.id.district_tab);
in onCreate
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With