【问题标题】:How to set multiline for navigationdrawer menu items?如何为导航抽屉菜单项设置多行?
【发布时间】:2016-11-02 11:44:10
【问题描述】:

如何在navigationdrawer中为菜单项设置多行(如果项目的文本不适合navigationdrawer的宽度?

【问题讨论】:

标签: android navigation-drawer


【解决方案1】:

将答案 https://stackoverflow.com/a/40575681/10824768 与 cmets 相结合找到了一个简单的解决方案

  • 向styles.xml 添加新样式
  • 为 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
  • 我尝试了其他几种解决方案,包括这个具有不同属性的解决方案,但这是唯一适合我的解决方案
【解决方案2】:

现在可以更轻松地完成 - 只需使用 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" />

【讨论】:

  • 它有效,但请记住使用com.google.android.material:material:1.1.0compileSdkVersion 29。
猜你喜欢
  • 2017-02-13
  • 2013-06-13
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
  • 2019-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多