[英]How to add sub menu into Bottom Navigation View
i want to add submenu into my bottom navigation view and how do add into bottom navigation view? 我想将子菜单添加到我的底部导航视图中,以及如何添加到底部导航视图中? i am try direct add into the menu item and it cannot run 我尝试直接添加到菜单项中,它无法运行
bottom_navigation_menu.xml bottom_navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu"
android:icon="@drawable/ic_menu"
android:title="@string/menu"
app:showAsAction="ifRoom"
android:enabled="true"/>
<item
android:id="@+id/promotion"
android:icon="@drawable/ic_promotion"
android:title="@string/promotion"
app:showAsAction="ifRoom"
android:enabled="true"/>
<item
android:id="@+id/order"
android:icon="@drawable/ic_order"
android:title="@string/order"
app:showAsAction="ifRoom"
android:enabled="true"/>
<item
android:id="@+id/location"
android:icon="@drawable/ic_location"
android:title="@string/location"
app:showAsAction="ifRoom"
android:enabled="true"/>
<item
android:id="@+id/more"
android:icon="@drawable/ic_more"
android:title="@string/more"
app:showAsAction="ifRoom"
android:enabled="true">
<menu>
<item
android:icon="@drawable/ic_more"
android:title="Sub item 1" />
<item
android:icon="@drawable/ic_more"
android:title="Sub item 2" />
</menu>
</item>
</menu>
For Add menu, you can use design:menu="@menu/bottom_navigation_menu"
to your Bottom Navigation View. 对于添加菜单,您可以在底部导航视图中使用design:menu="@menu/bottom_navigation_menu"
。
Currently, You can't use subMenu in BottomNavigationView and only use maximum 5 menu items. 当前,您不能在BottomNavigationView中使用subMenu,最多只能使用5个菜单项。
Check BottomNavigationView android developer doc. 检查BottomNavigationView android开发人员文档。
If you want to have submenu for a menu item, your best shot is to have it in Navigation drawer as you cannot create a submenu inside BottomNavigationView. 如果要为菜单项设置子菜单,最好的选择是将其放在导航抽屉中,因为您无法在BottomNavigationView中创建子菜单。
Also, as per material design guidelines, there should be only 3 to 5 top level destinations(or menu items) in our BottomNavigationView. 另外,根据材料设计指南,在BottomNavigationView中应该只有3到5个顶级目标(或菜单项)。 If you have less than 3 items, it is recommended to use tabs. 如果少于3个项目,建议使用选项卡。 And if you have more than 5 items, it is recommended to have the rest items inside Navigation drawer. 并且如果您有5个以上的项目,建议将其余项目放在“导航”抽屉中。 Please refer the link below: 请参考以下链接:
https://material.io/guidelines/components/bottom-navigation.html https://material.io/guidelines/components/bottom-navigation.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.