Can I alter the default behavior of the action bar items menu so the menu doesn't close automatically when any of its items is checked ?
I tried returning false to OnOptionsItemSelected method. Also , I tried to add this line to OnCreateOptionsMenu
menu.PerformIdentifierAction(Resource.Id.fs_action_statusFilter, MenuPerformFlags.PerformNoClose);
You can add a sub menu to an item in your menu by adding a menu element as the child of an item. So the sub menu will open when its parent menu is checked. For example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/file"
android:title="#string/file" >
<!-- "file" submenu -->
<menu>
<item android:id="#+id/create_new"
android:title="#string/create_new" />
</menu>
</item>
</menu>
Related
I want to implement Dialog where I will be able to set values.
I also would want to Dialog will Popup when I click on three dots (Menu) on Toolbar.
So far I've got menu
<?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_allclients_min_date"
android:orderInCategory="200"
android:title="#string/menu_min_date"
app:showAsAction="never" />
<item
android:id="#+id/menu_allclients_max_date"
android:orderInCategory="201"
android:title="#string/menu_max_date"
app:showAsAction="never" />
<item
android:id="#+id/menu_allclients_min_amount"
android:orderInCategory="202"
android:title="#string/menu_min_amount"
app:showAsAction="never" />
<item
android:id="#+id/menu_allclients_max_amount"
android:orderInCategory="203"
android:title="#string/menu_max_amount"
app:showAsAction="never" />
Now, when Menu is clicked it show as list of four items. But It isn't a way I want to implement it.
I would also know is there any listener when Menu icon( three dots ) is clicked. It would solve my problem.
For help i sugest, if you dont have more than 2 menu itens, make a menu item set the 3 dots as icon and always as showasaction. After that in on menu item selected in your activity make a switch to check item selected and if is the 3 dots item make the dialog.
I'm using topup sub-menu item by group in menu item. I have created group item menu as given below menu xml code.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cycle="http://schemas.android.com/apk/res-auto" >
<group>
<item
android:id="#+id/bookAppt"
android:icon="#drawable/addsomething_gray"
android:orderInCategory="1"
android:title="Book Appointment"
cycle:showAsAction="never"/>
<item
android:id="#+id/refreshAppt"
android:icon="#drawable/refresh_icon_dark"
android:orderInCategory="2"
android:title="Refresh"
cycle:showAsAction="never"/>
</group>
Every thing going perfect but submenu item icon not showing. Can anyone guide me regarding this issue.
Thanks
In your code change this cycle:showAsAction="never" to cycle:showAsAction="always".
replace cycle:showAsAction="never" with app:showAsAction="ifRoom|always"
Menu item showing on both never and always states
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:apptivo="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_create"
android:icon="#drawable/ic_action_new_white"
android:orderInCategory="2"
android:title="#string/create_string"
apptivo:showAsAction="always" />
</menu>
check if your menu is being created more than once, if have Activity or fragment that creates the menu, and class that it extend is creating the same menu you would have this. more over if you are creating the menu in the fragment and the fragment is being add more than once you would see this
Im working on action menu item and its over flow item this is my main_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_search"
android:icon="#drawable/search"
android:title="#string/start_new_project"
app:showAsAction="always" />
<item
android:id="#+id/menu_dts_overflow"
android:icon="#drawable/ic_action_overflow_round"
android:orderInCategory="11111"
android:title="Service"
app:showAsAction="always">
<menu>
<item
android:id="#+id/menu_newProject"
android:icon="#drawable/newproject"
android:title="#string/start_new_project"
app:showAsAction="never" />
<item
android:id="#+id/menu_help"
android:icon="#drawable/help"
android:title="Service Tasks"
app:showAsAction="never" />
<item
android:id="#+id/menu_signOut"
android:icon="#drawable/signout"
android:title="#string/menusignout"
app:showAsAction="never" />
</menu>
</item>
I tried to construct a search item and a overflow item which you can see in the above code. I'm new to Action bar menu items so i tried to Google it and was able to make it work as I need.
In this I have to know one more thing.
1. What is orderInCategory with some numbers and what for it is used..?
android:orderInCategory is an integer attribute that dictates the order in which the menu items will appear within the menu when it is displayed.
<menu
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_item_first"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/string_one"/>
<item
android:id="#+id/menu_item_second"
android:orderInCategory="2"
android:showAsAction="never"
android:title="#string/string_two"/>
</menu>
Menu items in ToolBar are arranged from left to right (or
start to end in RTL mode) in the ascending order (i.e. 1,2,3 ->
left to right).
Menu Items in Overflow menu are arranged from top to bottom in
the ascending order (i.e. 1,2,3 -> top to bottom).
android:orderInCategory is actually useful in two ways.
1. For menu items in ActionBar.
Items will appear from left to right in ActionBar depending on the ascending order.
2. For menu items in overflow menu.
Overflow menu items will be displayed from top to bottom depending upon the ascending order you have specified.
android:orderInCategory Higher value, lower priority.
I have a Activity and a Fragment in it, both of them have option menu, and the item numbers are 1 and 3.
If I set android:orderInCategory=0, the activity menu are above the fragment menu, same effect before I set the value.
But if I set android:orderInCategory=1,the activity menu are below the fragment menu, and that is what I want.(I also test android:orderInCategory=5 tested too, still the same effect.)
I want to display an overflow menu in the action bar , I tried to use a menu in my activity but I'm only getting a popup menu when I click on the menu button on my phone. Is there any way to force that overflow menu for phone with physical buttons ?
Here is my menu file :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom"/>
<item
android:id="#+id/computer"
android:title="computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom"/>
<item
android:id="#+id/gamepad"
android:title="gamepad"
android:icon="#drawable/gamepad"
android:showAsAction="ifRoom"/>
</menu>
You need to go into the menu xml file and make sure it has
android:showAsAction="ifRoom"
and for the icon you use
android:icon="#drawable/yourIcon"
Edit: To make sure you are using the right menu xml, check your activity class that is being run and look for the
onCreateOptionsMenu(Menu menu)
Once you have found that check that the line
getMenuInflater().inflate(R.menu.{0}, menu);
matches your menu xml file, where {0} = your xml file name