2

I need to hide center bottom tab in the bottom navigation while launching the app. Here I have tried to remove the tab. It worked in potrait mode, But in the landscape mode, to hide the tab bar in UI.

bottomNavigation.getMenu().removeItem(R.id.schedulers);



<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/"
        android:icon="@drawable/ic_bottom"
        android:title="@string/all"/>

    <item
        android:id="@+id/tab"
        android:icon="@drawable/ic_bottom"
        android:title="@string/my"/>

    <item
        android:id="@+id/schedulers"
        android:icon="@drawable/schedulers"
        android:title="@string/schedulers"/>

    <item
        android:id="@+id/tab"
        android:icon="@drawable/ic_bottom"
        android:title="@string/kkk"/>
    <item
        android:id="@+id/tab"
        android:icon="@drawable/ic_bottom"
        android:title="@string/kkkk"/>
</menu>

enter image description here

sejn
  • 2,040
  • 6
  • 28
  • 82
  • This should work in any orientation; unless `bottomNavigation.getMenu().removeItem(R.id.schedulers)` is called under certain conditions; where do you call this? – Zain Jan 08 '22 at 18:13
  • I have called this in the MainActivity onNavigationTabSelected() method – sejn Jan 10 '22 at 03:42
  • If you want to keep this hidden by default, then call it from a lifecycle method like `onCreate()`; then show it whenever you want – Zain Jan 10 '22 at 04:58
  • @Zain After adding it in the oncreate it works fine for me, – sejn Jan 10 '22 at 10:48

3 Answers3

1

Just use listener on navController if using nav component

navController.addOnDestinationChangedListener { _, destination, _ ->
   if(destination.id == R.id.full_screen_destination) {
       toolbar.visibility = View.GONE
       bottomNavigationView.visibility = View.GONE
   } else {
       toolbar.visibility = View.VISIBLE
       bottomNavigationView.visibility = View.VISIBLE
   }
}

Refrence

0

Are you using two layout for this app like portrait and landscape?

If this is the case, immediately delete the landscape file OR add the same bottom navigation with very same id. Because I was facing on. this issue lady and finally I resolved it in this way.

Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38
0

If we add it in the onCreate() methods it will works fine and able to hide the tab with the code

bottomNavigation.getMenu().removeItem(R.id.schedulers)
sejn
  • 2,040
  • 6
  • 28
  • 82