8

Implementing a 5-item BottomNavigationView -with the labels always shown- I'm using the following approach:

<android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation"
        app:labelVisibilityMode="labeled"/>

Unfortunately, the result hyphenates words when active, as shown in the picture:

Hyphenated active label

I tried setting different styles for the label's active text:

app:itemTextAppearanceActive="@style/text_navigation_active_labels"

-- styles.xml --

<style name="text_navigation_active_labels">
    <item name="android:breakStrategy">simple</item>
    <item name="android:hyphenationFrequency">none</item>
</style>

But the result is exactly the same (whether I only use break strategy, hyphenationFrequency or both). I'm currently testing it on an API 27 physical phone.

Any help is appreciated.

Community
  • 1
  • 1
Julián M.
  • 912
  • 8
  • 11

1 Answers1

16

As 5 items might be a lot of space, it is necessary to compromise text size. In order to fix it, adding a custom style to the BottomNavigationView text gets the job done:

 <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        ...
        app:itemTextAppearanceActive="@style/navTextActive"
        app:itemTextAppearanceInactive="@style/navTextInactive"/>

on styles.xml:

<style name="navTextInactive">
    <item name="android:textSize">11sp</item>
</style>

<style name="navTextActive">
    <item name="android:textSize">12sp</item>
</style>

Result:

FixedNavBar

Hope it can help anyone out there!

Julián M.
  • 912
  • 8
  • 11
  • Why it show "attribute :itemTextAppearanceActive not found" in my fragment layout? – quangkid Sep 18 '18 at 16:37
  • @quangkid you need to add android:theme="@style/MaterialBaseTheme" to your view xml and then add to your style file , also add implementation 'com.google.android.material:material:1.1.0-alpha10' to your build.gradle – Ahmed na Sep 19 '19 at 02:45