6

How to set multiline for menu items in navigationdrawer (if item's text doesn't fit to navigationdrawer width?

user3352926
  • 1,017
  • 1
  • 10
  • 15

2 Answers2

10

Combining answer https://stackoverflow.com/a/40575681/10824768 with comments found an easy solution

  • Add a new style to the styles.xml
  • Set the new style to the NavigationView

res / values / styles.xml

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

res / layout / activity_main.xml

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    app:theme="@style/TextAppearance" />
jbar
  • 101
  • 1
  • 3
9

Right now it can be done much easier - just use app:itemMaxLines="2"

<com.google.android.material.navigation.NavigationView
  android:id="@+id/nav_side_view"
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:layout_gravity="start"
  android:fitsSystemWindows="false"
  app:headerLayout="@layout/view_nav_header"
  app:itemMaxLines="2"
  app:menu="@menu/nav_menu" />
Ievgen
  • 426
  • 6
  • 10