How to add sub menu into Bottom Navigation View - android

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>

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.

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

Related

Swipe the menu items of bottom navigation bar

I am trying to add 4 items in menu of Bottom Navigation View but I cant figure out how to make it swipeable. The screenshot looks like this. I have figured out the increase in size but once I get to know the swiping so that a complete name can be visible or either wrap text can be applied.
My menu file is;
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_1"
android:title="Triggered Insan" />
<item
android:id="#+id/menu_2"
android:title="Carry Minati" />
<item
android:id="#+id/menu_3"
android:title="Hadd Bc" />
<item
android:id="#+id/menu_4"
android:title="Lakshay Chaudhary" />
</menu>

Android navigation app change the icon of listed menus

I have use this code for menu icon but does not displayed in app why?
Please help me to to display icon left side of navigation menu list
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/income"
android:icon="#drawable/ic_income"
android:title="Income" />
<item
android:id="#+id/expense"
android:icon="#drawable/ic_expense"
android:title="Expense" />
<item
android:id="#+id/nav_settings"
android:icon="#drawable/ic_setting"
android:title="#string/nav_settings" />
</group>
</menu>
We have to set icon list as null then only it display the icon in navigation menu list
For that use following this code
navigationView.setItemIconTintList(null);

How to programatically add menu item to submenu that is created in XML by findViewById in Android Navigation View?

I am developing an android app using Android Studio. I am working with navigation drawer and navigation view. I know how to programmatically add sub menu to navigation view. But there is a slight different for what I want to do.
Normally I add submenu like this to navigation view
Menu menu = leftDrawer.getMenu();
SubMenu authSubMenu = menu.addSubMenu(22,22,96,"Settings");
authSubMenu.add(22,getResources().getInteger(R.integer.logout_item_id),99,"Sign out");
But what I want is different. I want to add items to submenu that is already created in XML file.
I have XML this file for navigation drawer menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/left_m_item_trendy_hot"
android:title="Trendy/Hot" />
<item
android:id="#+id/left_m_item_male"
android:title="Male" />
<item
android:id="#+id/left_m_item_female"
android:title="Female" />
<item
android:id="#+id/left_m_item_designers"
android:title="Designers/Community" />
</group>
<item
android:id="#+id/category_menu"
android:title="Categories"
android:layout_gravity="bottom">
<menu>
<item
android:title="Sub item 1" />
<item
android:title="Sub item 2" />
</menu>
</item>
</menu>
I want to do something like this
subMenu = findViewById(R.id.category_menu);
subMenu.add("Item 1");
Is this possible?
To get to the Submenu you can do something like below, and then add the menu item to it.
Code as follows:
SubMenu subMenu = navigationView.getMenu().findItem(R.id.category_menu).getSubMenu();
subMenu.add("Sub item 3");
subMenu.add("Sub item 4");

How to hide action bar on clicking search menu item and display when search is done?

I've an action bar and three tabs each includes some list to display.
When I click search I want the rest of the action bar should be hidden except the list in a tab and search item it self should be enabled, where want to search.
How can I achieve it?
Edit:
<?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">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item
android:id="#+id/action_search"
android:title="#string/action_search"
android:orderInCategory="100"
android:icon="#drawable/ic_action_search"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:id="#+id/home"
android:icon="#drawable/icon_home"
android:title="Home" />
<item android:id="#+id/totalCash"
android:icon="#drawable/icon_delivered"
android:title="Cod" />
<item android:id="#+id/statusForEach"
android:icon="#drawable/icon_cancelled"
android:title="Status" />
<item android:id="#+id/logout4"
android:icon="#drawable/icon_cancelled"
android:title="Logout" />
<!--<item android:id="#+id/menu_delete"
android:icon="#drawable/icon_delete"
android:title="Delete" />
<item android:id="#+id/menu_preferences"
android:icon="#drawable/icon_preferences"
android:title="Preferences" />-->
add below line to all menu items except search
app:showAsAction="ifRoom"
and in your search item add
app:iconifiedByDefault="true"
You have to implement MenuItemCompat interface to get those events. that will allow you to listen open and close and many more events. so check it.

How to hide the actionbar menu item based on tab layout?

I have a actionbar_layout and three tabs in my android application.The actionbar_layout is common for all the three tabs(Event tab,Invitation tab,Groupchat tab).The actionbar_layout have 3 icons(dropdown,event icon & settings icon). I need to visible that icons based on tab click,for example when ontap invitation tab "settings icon" only visible in actionbar layout,if click event tab only "event icon" need to be visible.Similarly when on tap Groupchat tab i need to visible "dropdown icon".
How to achieve this please help me
My menu_user_dashboard.xml code is below
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appmunu="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="ringee.app.com.ringeeapp.UserDashBoard">
<item
android:id="#+id/dropdown"
android:icon="#drawable/dropdown_icon"
android:title="Dropdown"
appmunu:showAsAction="always">
<menu>
<item
android:id="#+id/all"
android:title="All" />
<item
android:id="#+id/event"
android:title="Event" />
<item
android:id="#+id/invitation"
android:title="Invitation" />
</menu>
</item>
<item
android:id="#+id/create_occasion"
android:icon="#drawable/ic_action_event"
android:title="Create Occasion"
appmunu:showAsAction="always" />
<item
android:id="#+id/account_settings"
android:orderInCategory="100"
android:title="#string/action_settings" />
<item
android:id="#+id/profile"
android:orderInCategory="100"
android:title="#string/profile_image" />
</menu>
you can hide or show menu item in OnCreateOptionsMenu on behalf of some flags
like when user select any item then set flag true for that item and call
invalidateOptionsMenu()
after this you can change visibility
MenuItem item = menu.findItem(R.id.menu_Done);
if (flag/condition)) {
item.setVisible(false);
} else { }

Categories

Resources