sejn
sejn

Reputation: 2644

How can I hide a bottom tab in the bottom navigation in android. (Landscape mode failed to hide the tab)

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

Upvotes: 2

Views: 1338

Answers (3)

amid aliaghazadeh
amid aliaghazadeh

Reputation: 68

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

Upvotes: 1

sejn
sejn

Reputation: 2644

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)

Upvotes: 1

Sambhav Khandelwal
Sambhav Khandelwal

Reputation: 3765

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.

Upvotes: 0

Related Questions