如何为导航抽屉菜单项设置多行显示?

6
如何在导航抽屉中为菜单项设置多行(如果项目文本不适合导航抽屉宽度)?

1
使用此链接:https://dev59.com/AVoV5IYBdhLWcg3wEraD - Akash Jagtap
1
请检查我的答案:https://dev59.com/AVoV5IYBdhLWcg3wEraD#43947132 - Farshad Tahmasbi
2个回答

10

结合回答https://dev59.com/AVoV5IYBdhLWcg3wEraD#40575681和评论,找到了一个简单的解决方案。

  • 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" />

完成了!这节省了我的时间!耶!@karakuku - Nice umang
我尝试了几种其他解决方案,包括使用不同的属性,但这是唯一适用于我的解决方案。 - or_dvir

9

现在这个操作可以更加轻松 - 只需使用 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" />

2
它可以工作,但请记得使用com.google.android.material:material:1.1.0compileSdkVersion 29。 - Misagh Emamverdi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接