JsLaw
JsLaw

Reputation: 163

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

<?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>

Upvotes: 1

Views: 3664

Answers (2)

Kunal
Kunal

Reputation: 412

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

Upvotes: 2

pRaNaY
pRaNaY

Reputation: 25310

For Add menu, you can use design:menu="@menu/bottom_navigation_menu" to your Bottom Navigation View.

Currently, You can't use subMenu in BottomNavigationView and only use maximum 5 menu items.

Check BottomNavigationView android developer doc.

Upvotes: 2

Related Questions