如何为导航抽屉中的菜单项设置多行(如果项目的文本不适合导航抽屉的宽度?
Combining answer https://stackoverflow.com/a/40575681/10824768 with comments found an easy solution
- 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" />
Right now it can be done much easier - just use 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" />
在菜单项布局中使用android:singleLine="false"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.