Home > Software design >  How to hide the fragment name/id from the toolbar when using BottomNavView and AppBarConfiguration
How to hide the fragment name/id from the toolbar when using BottomNavView and AppBarConfiguration

Time:12-31

I have an activity, where i setup the Bottom Navigation View and appCompat toolbar. And I write the code like this. my code to handle toolbar and bottom nav view

But due to this, my toolbar shown like this. which i don't want. my toolbar now

How can i hide the fragment name from my toolbar?

CodePudding user response:

Try using a menu for the bottomNavigation items instead

Create a menu_item.xml in your res/menu The code:


<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@ id/home"
        android:enabled="true"
        android:title="Home" />


    <item
        android:id="@ id/account”
        android:title="Account" />


    <item
        android:id="@ id/more_Fragment"
        android:title =“ ”
    />


</menu>

You can then set the title to be displayed or leave it empty which solves your problem

Then you assign the menu to the bottomnavbar xml like this :


<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@ id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@android:color/white"
        app:itemIconTint="@android:color/black"
        app:itemTextColor="@android:color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="1.0"
        app:menu="@menu/menu_item" />

Then you have something like this for the bottom navigation

CodePudding user response:

I simply hide title by using the following code.

supportActionBar?.let { it ->
     it.title = ""
}
  • Related