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 { }
Related
Android app has one top level menu named "Organisation" which gets displayed on the click of ellipsis (3 dots).
On touching this menu, pop up submenu gets displayed with top item as Organisation.
I want to hide this top level menu
and
only show 2 items in the sub pop up menu.
"Register Org" and "Change Org" are apps 2 sub popup menu items.
How do I do that? I tried below code which doesn't work.
MenuItem topLevelMenuOrganisation = menuList.findItem(R.id.idMenuOrganisation);
topLevelMenuOrganisation.setVisible(false);
Menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.jayantbhave.menuapps.MainActivity">
<item
android:id="#+id/idMenuOrg"
android:title="Organisation">
<menu>
<item
android:id="#+id/idMenuRegisterOrg"
android:title="Register Org" />
<item
android:id="#+id/idMenuChangeOrg"
android:title="Change Org" />
</menu>
</item>
</menu>
You can remove the "Organisation" item from the menu. Write your menu as following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.jayantbhave.menuapps.MainActivity">
<item
android:id="#+id/idMenuRegisterOrg"
android:title="Register Org" />
<item
android:id="#+id/idMenuChangeOrg"
android:title="Change Org" />
</menu>
Hope it helps!
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
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);
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.
I am using an actionbar with actionbar tab in an app. i have menu item and three tab with home icon in actionbar.
BUT When i run this app on emulator if menu item has property showAsAction with value "ifroom" then some of them are appear because of no more room
but the menu icon at the right upper corner is missing everytime i run this app.
Here is the image what is come in emulator :
and image below what i need :
here is my code for menu.xml:
<item android:id="#+id/menu_add" android:title="Add" android:icon="#drawable/icon" />
<item android:id="#+id/menu_DashBoard" android:title="DashBoard" />
<item android:id="#+id/menu_Master_Entry" android:title="Master Entry" />
<item android:id="#+id/menu_Product_Section" android:title="Product Section" />
<item android:id="#+id/menu_Retailers_Orders" android:title="Retailers Orders" />
<item android:id="#+id/action_search" android:icon="#drawable/search_icon"
android:title="Search" android:showAsAction="ifRoom" android:layout_gravity="left"/>
<item android:id="#+id/action_calender" android:title="Calender"
android:showAsAction="ifRoom" android:icon="#drawable/calender" android:layout_gravity="left" />
<item android:id="#+id/action_message" android:title="Message"
android:showAsAction="ifRoom" android:icon="#drawable/messageicon" android:layout_gravity="left"/>
Please help .. why it is come and what is the solution of this problem?
THANKS in advance. I only want that this menu dropdown at the last in actionbar should be shown in each screen size but it disappear in phone and shown on tab(10.1)
You can change android:showAsAction="ifRoom" to android:showAsAction="always"but this is not recommended.
If there is not enough room this items are added to more option at the end of the action bar where thr title of this item is shown in a drop-down (kind of) list.