I have an app with a Navigation View for my DrawerLayout. I add programmatically items in the menu because I receive the information over the network. But sometimes, an item name can be very long and is just cut off with even having the ellipsize icon "..."
Does someone have an idea on how to have multiline for my menu items?
Thanks
Override design_navigation_menu_item.xml from the Android Support Design Library and modify the things you need (set
android:ellipsize="end"
andandroid:maxLines="2"
)Your res/layout/design_navigation_menu_item.xml should look like this:
However, you should just ellipsize the text to properly follow the Material Design guidelines.
You have not to override anything to just ellipsize the text:
NavigationView
res / values / styles.xml
res / layout / activity_main.xml
I had the same problem and I tried and tried, There was no progress with
Menu
, I don't say it was impossible but I couldn't find a way to breakMenuItem
lines.But if you don't insist on using
Menu
I suggest you to use aListView
orRecyclerView
in your layout like this:As you can see there is no special thing to explain, no menu, just a
RecyclerView
,layout_marginTop
value is same as header height, I'm sure you know the rest of the story (How to fire upRecyclerView
), This approach gives more flexibility toNavigationView
menu items (actuallyRecyclerView
items). If my answer is not clear enough to you let me know.Here is the result:
You shouldn't change that.
Check out the material design guideline: https://material.io/design/components/navigation-drawer.html#anatomy
Check out this answer. Default android slide menu is not very flexible, most likely you will have to create your custom view.
I really this tutorial from AndroidHive.