5

Problem : NavigationView not show full text of menu item, also not truncate text.

This item I see correctly - two words "Small title":

<item
android:id="@+id/example1"
android:icon="@drawable/filter_2"
android:title="Small title"
android:checked="false"
app:actionLayout="@layout/menu_counter" />
/>

And with next item - I see only first two words "Small title" without any truncate of next word "andveryverylongword":

<item
android:id="@+id/example2"
android:icon="@drawable/filter_2"
android:title="Small title andveryverylongword"
android:checked="false"
app:actionLayout="@layout/menu_counter" />
/>

Widget :

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
ndroid: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"/>

Also : AndroidStudio 1.5, support library.

EDITED : Here is example of standart project "Navigation Drawer Activity" in Android Studio.

activity_main_drawer.xml : menu

in mobile : not see long word

DQuade
  • 303
  • 3
  • 10

2 Answers2

7

I just got this working * Override design_navigation_item.xml and change it to use android:layout_height="wrap_content" android:minHeight="?android:listPreferredItemHeightSmall"

  • Override design_navigation_menu_item.xml to use maxLines=2

Kinda cool, I can't believe that works. Thanks to the guy on stackoverflow that talked about overriding icon size, which helped me thinking in this direction.

nAndroid
  • 862
  • 1
  • 10
  • 25
  • 1
    I have similar problem described in http://stackoverflow.com/questions/36157300/how-to-set-ellipsize-in-menu-item-of-navigationview. Could you provide more information about overriding design_navigation_menu_item.xml? – Aleksander Mielczarek Mar 22 '16 at 16:56
  • 1
    @AleksanderMielczarek Basically just copy and paste the code from file:/usr/local/google/buildbot/src/googleplex-android/mnc-supportlib-release/frameworks/support/design/res/layout/design_navigation_menu_item.xml into a new design_navigation_menu_item.xml you make in your /rest/layout directory and then modify the things you need. Spelunk the source code as needed to see if you need to override subheader or any of the rest. I still haven't figured out the compound drawable yet, if it can be lined up to the left top like a bullet point instead of the center. – nAndroid Mar 23 '16 at 15:08
4

Add app:itemMaxLines="2" in NavigationView of your layout. That worked for me.

<com.google.android.material.navigation.NavigationView
            android:id="@+id/navigation_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            app:itemMaxLines="2"
            android:background="@color/background_color"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />