Search code examples
androidandroid-bottomnavbottombar

How to add second line to text on bottom bar for Android?


I'm trying to have my text go down to a second line so it's not cut off but not sure whether this is possible using the Google MaterialBottomBar? Something like the image below please.

enter image description here

But this is what I have:

enter image description here

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/white"
        app:labelVisibilityMode="labeled"
        app:itemIconTint="@drawable/nav_items_color"
        app:itemTextColor="@drawable/nav_items_color"
        app:menu="@menu/bottom_menu_nav" />

Thank you.


Solution

  • Add a style to BottomNavigation in style.xml

    <style name="BottomNavigationStyle">
            <item name="android:lines">2</item>
        </style>
    

    And then use above style in your xml

    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNav"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/white"
            app:labelVisibilityMode="labeled"
            app:itemIconTint="@drawable/nav_items_color"
            app:itemTextColor="@drawable/nav_items_color"
            android:theme="@style/BottomNavigationStyle"
            app:menu="@menu/bottom_menu_nav" />