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
Related
I'm using AndroidX Navigation architecture and want to know is it possible to replace the ActionBar menu completely or not?
In the project, in the Menu directory, there is a home.xml file that contains a menu items:
<?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"
android:id="#+id/homeMainMenu">
<item
android:id="#+id/action_inbox"
android:icon="#drawable/ic_baseline_mail_outline_24"
android:title="#string/action_inbox"
app:showAsAction="ifRoom" />
<item android:icon="#drawable/ic_baseline_more_vert_24"
android:title="#string/app_name"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action_exitapp"
android:icon="#drawable/ic_baseline_exit_to_app_24"
android:title="#string/action_exit"
app:showAsAction="never" />
</menu>
</item>
</menu>
I want to create another menu XML file like mymenu.xml and on the fragment replace it with the home menu. Because of some reason don't want to replace items.
Is it possible? If "Yes" how to handle item click?
If i got your question correct then i guess you want to create different menu for activity and its fragment. You can do that. Please check here
Remember you've to add hasOptionsMenu in fragment onCreate
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.
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>
Is it possible to add Action Item in ActionBar, which show drop down menu on click?
paint example:
P.S. ActionBar already contains navigation drawer toggle button, title and overflow menu.
Where do I initialize that button, in which xml?
How do I set such drop down operations to Action Item?
How to set the content of such drop down menu?
And how to get access to specific item click action?
Some working code examples would be great!
Thanks in advance. Appreciate any help.
So I found solution by myself.
You need to inflatean Action Item in onCreateOptionsMenu(Menu menu):
getMenuInflater().inflate(R.menu.global_filters, menu);
global_filters.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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".NavigationActivity">
<item android:id="#+id/action_filters"
android:title="Фильтры"
android:icon="#drawable/ic_filter_white"
android:orderInCategory="100"
app:showAsAction="ifRoom" />
</menu>
...which is that downside arrow:
Then create a PopupMenu. I did it in onOptionsItemSelected:
View menuItemView = findViewById(R.id.action_filters); // SAME ID AS MENU ID
PopupMenu popupMenu = new PopupMenu(this, menuItemView);
popupMenu.inflate(R.menu.popup_filters_user);
popupMenu.show();
and here you set .xml file with items of drop down menu in file popup_filters_user.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/filter_bought_user"
android:title="Купленые"/>
<item
android:id="#+id/filter_price_user"
android:title="Цена"/>
<item
android:id="#+id/filter_author_user"
android:title="Автор"/>
</menu>
and hooray! Here's the result:
If your menu is in a Fragment then you might use the following to get the View
View menuItemView = MainActivity.getInstance().getWindow().findViewById(R.id.action_filters);
I am backporting my app to API7 with AppCompat and have a problem with the actionbar.
When I use FragmentActivity the actionbar is shown on my phone (API18), but with ActionBarActivity it shows up as the optionmenu by pressing the menubutton.
On the emulator with API7 the actionbar is always shown as an optionsmenu.
Any ideas?
Use the compat name space for your menu items like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_whatever"
android:icon="#drawable/ic_action_whatever"
android:title="#string/whatever"
compat:showAsAction="ifRoom" />
</menu>
Related to a duplicate that points to this post, I was having trouble making my buttons appear as action items instead of overflow items, despite having showAsAction set to always. I managed to coerce it by extending my activity with Activity instead of ActionBarActivity. According to this answer, this is acceptable if you don't need to support api levels below 11.
...extends ActionBarActivity:
...extends Activity:
I do debug with Doogee Valencia Y100Pro, and menu as "three little square" not visible, but when I extended my MainActivity with android.support.v7.app.ActionBarActivity, then I obtain text/icon menu in action bar. Next screenshot and 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/action_update"
android:icon="#drawable/ic_refresh"
android:title="#string/action_update"
app:showAsAction="always"/>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="ifRoom"/>
</menu>