Navigation View multiline text

I have a navigation view app for my DrawerLayout. I add program elements to the menu because I get information over the network. But sometimes the name of the element can be very long and just cropped even with the ellipsis icon "..."

Does anyone have an idea on how to have multi-line for my menu items?

thank

+8
source share
5 answers

Reinstall the design_navigation_menu_item.xml file from the Android support design library and change the things you need (install android:ellipsize="end"and android:maxLines="2")

Your res / layout / design_navigation_menu_item.xml should look like this:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <CheckedTextView
        android:id="@+id/design_menu_item_text"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:drawablePadding="@dimen/design_navigation_icon_padding"
        android:gravity="center_vertical|start"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        android:ellipsize="end"
        android:maxLines="2" />
    <ViewStub
        android:id="@+id/design_menu_item_action_area_stub"
        android:inflatedId="@+id/design_menu_item_action_area"
        android:layout="@layout/design_menu_item_action_area"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />
</merge>

, , Material Design.

- :

  • styles.xml
  • NavigationView

res/values ​​/styles.xml

<style name="TextAppearance">
    <item name="android:ellipsize">end</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" />
+20

. Android , , .
AndroidHive.

0

, , Menu, , , MenuItem.

Menu, ListView RecyclerView , :

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/nav_draw_header">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_marginTop="160dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.design.widget.NavigationView>

, , , RecyclerView, layout_marginTop , , , ( RecyclerView). NavigationView ( RecyclerView ).   , .

:

enter image description here

0

Just add the attribute app:itemMaxLines="2"to the NavigationView tag as follows:

<com.google.android.mayerial.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:itemMaxLines="2" />

NOTE: Material dependence is--

implementation 'com.google.android.material.material:1.0.0'
0
source

All Articles