Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NavigationView : not show full item and not truncate

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

like image 687
DQuade Avatar asked Feb 24 '16 11:02

DQuade


2 Answers

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.

like image 126
nAndroid Avatar answered Oct 20 '22 11:10

nAndroid


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" />
like image 42
Ahsan Ullah Rasel Avatar answered Oct 20 '22 10:10

Ahsan Ullah Rasel