How to set multiline for menu items in navigationdrawer (if item's text doesn't fit to navigationdrawer width?
Asked
Active
Viewed 4,223 times
6
-
1Use this link :http://stackoverflow.com/questions/36729974/navigation-view-multiline-text – Akash Jagtap Feb 10 '17 at 07:37
-
1check my answer: http://stackoverflow.com/a/43947132/5836953 – Farshad May 12 '17 at 22:13
2 Answers
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
-
-
i tried several other solutions including this one with different attributes, but this is the only one that works for me – or_dvir Dec 05 '19 at 15:21
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
-
2It works but remember to use `com.google.android.material:material:1.1.0` and `compileSdkVersion` 29. – Misagh Emamverdi Jun 24 '20 at 10:10