如何将子菜单添加到底部导航视图中

时间:2017-04-05 08:51:21

标签: android submenu bottomnavigationview

我想在我的底部导航视图中添加子菜单 以及如何添加到底部导航视图? 我尝试直接添加到菜单项,它无法运行

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>

2 个答案:

答案 0 :(得分:1)

对于“添加”菜单,您可以使用design:menu="@menu/bottom_navigation_menu"到底部导航视图。

目前,您无法在BottomNavigationView中使用subMenu,并且只能使用最多5个菜单项。

检查BottomNavigationView android开发者文档。

答案 1 :(得分:1)

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.

Also, as per material design guidelines, there should be only 3 to 5 top level destinations(or menu items) in our BottomNavigationView. If you have less than 3 items, it is recommended to use tabs. And if you have more than 5 items, it is recommended to have the rest items inside Navigation drawer. Please refer the link below:

https://material.io/guidelines/components/bottom-navigation.html