My main file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_settings">
<menu>
<item
android:id="#+id/menu_adhoc1"
android:icon="#drawable/icon_custom"
android:title="#string/menuitem2_3"/>
<item
android:id="#+id/cPanel1"
android:icon="#drawable/icon_cpanel"
android:title="#string/menuitem2_5"/>
<item
android:id="#+id/tutorial1"
android:icon="#drawable/icon_tutorial"
android:title="#string/menuitem2_4"/>
</menu>
</item>
</menu>
What I am trying to achieve is that place three more options under the menu, however I get only one option under menu labelled as "Settings", clicking on this leads to the desired result of getting three options under the menu. Where am I going wrong, any hints?
The problem is that you nested a <menu> containing <item>s inside another <item>.
As per the Menu documentation, this adds your second menu as a submenu of the parent item.
What it sounds like you are looking for is all the items being withing the same menu, like so:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_settings" />
<item
android:id="#+id/menu_adhoc1"
android:icon="#drawable/icon_custom"
android:title="#string/menuitem2_3"/>
<item
android:id="#+id/cPanel1"
android:icon="#drawable/icon_cpanel"
android:title="#string/menuitem2_5"/>
<item
android:id="#+id/tutorial1"
android:icon="#drawable/icon_tutorial"
android:title="#string/menuitem2_4"/>
</menu>
Related
As you can see, I am using Icon with each and every Menu Item, Main and Inner both the Menu Items contains Icon.
Issue: Showing Icons for Inner Menu Items, but not for Main Menu Items
1. Showing Icons for `Inner 1` and `Inner 2`
2. Not showing for `Main 1` and `Main 2`
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.akoscz.youtube.YouTubeActivity" >
<item
android:id="#+id/action_settings1"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Main 1"
app:showAsAction="never">
<menu>
<item
android:id="#+id/action_settings2"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Inner 1"
app:showAsAction="never"/>
<item
android:id="#+id/action_settings3"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Inner 2"
app:showAsAction="never"/>
</menu>
</item>
<item
android:id="#+id/action_settings4"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Main 2"
app:showAsAction="never"/>
</menu>
Actually I was tried thing same before unfortunately not find any solution so I just go trough this possible solution.
Made a parent menu a showAlways it will keep your icon visible in action bar area and it will open your submenu.
<item
android:id="#+id/action_settings1"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Main 1"
app:showAsAction="showAlways">
I am using Navigation Drawer menu without the header. The first item in the menu is too close to the top bar. How can I create margin for the first item? I am using this drawer menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Home"
android:id="#+id/nav_item_home"
android:icon="#drawable/ic_home_black_24dp"/>
<item android:title="Search Definitions"
android:id="#+id/nav_item_search"
android:icon="#drawable/ic_search_black_24dp"/>
<item android:title="About">
<menu>
<item android:title="About this app"
android:id="#+id/nav_item_about"
android:icon="#drawable/ic_info_black_24dp"/>
<item android:title="How to use this app"
android:id="#+id/nav_item_howtouse"
android:icon="#drawable/ic_perm_device_information_black_24dp"/>
</menu>
</item>
The outcome is this:
What I did as a workaround is to wrap the first item in a item menu with a blank title ... like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="">
<menu>
<item android:title="Home"
android:id="#+id/nav_item_home"
android:icon="#drawable/ic_home_black_24dp"/>
<item android:title="Search Definitions"
android:id="#+id/nav_item_search"
android:icon="#drawable/ic_search_black_24dp"/>
</menu>
</item>
<item android:title="About">
<menu>
<item android:title="About this app"
android:id="#+id/nav_item_about"
android:icon="#drawable/ic_info_black_24dp"/>
<item android:title="How to use this app"
android:id="#+id/nav_item_howtouse"
android:icon="#drawable/ic_perm_device_information_black_24dp"/>
</menu>
</item>
And then the outcome is exactly what I wanted:
Can someone please confirm if this workaround is the only way or is there any correct way of achieving the desired output.
Bit late, but any solution?
I've just played around in the xml:
<android.support.design.widget.NavigationView>
...
android:layout_marginTop="?attr/actionBarSize"
android:paddingTop="somePaddingValueInSp"
...
/>
I want to display overflow menu in android actionbar.
In all device i need same design app name at left side of actionbar and overflow icon at right side with menu in it.
Currently when i run app menu are showing on clicking of menu icon.
I just want to show menu like attached image-
below is my code inside menu.xml -
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_red"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/news"/>
<item
android:id="#+id/menu_green"
android:orderInCategory="2"
android:showAsAction="never"
android:title="#string/online_test"/>
how to show menu in such way.
Thanks in advance.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="always"
<menu>
<item
android:id="#+id/menu_red"
android:title="red"/>
<item
android:id="#+id/menu_green"
android:title="green"/>
</menu>
</item>
this worked for me maybe work for you too
When I do like this it works:
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
android:icon="#android:drawable/ic_dialog_map"
app:showAsAction="always"/>
But if I take icon from app drawable:
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
android:icon="#drawable/ic_action_place"
app:showAsAction="ifRoom"/>
the menu item doesn't show up nor in the menu nor in the action bar either.
Full 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_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
android:icon="#android:drawable/ic_dialog_map"
app:showAsAction="always"/>
<!--android:icon="#drawable/ic_action_place"-->
</menu>
What can be a problem?
Try this,
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
<!--android:icon="#android:drawable/ic_dialog_map"-->
<!-- need to add an order-->
android:orderInCategory="200"
android:icon="#drawable/ic_action_place"
app:showAsAction="always"/>
In situations like that changing icon color or app theme may helps ))
I have set three action items which am adding to the ABS through menu XML like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_share_app"
android:icon="#drawable/share_ab"
android:showAsAction="collapseActionView"
android:title="#string/menu_share_app"/>
<item
android:id="#+id/menu_search"
android:icon="#drawable/share_ab"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/share_ab"
android:showAsAction="collapseActionView"
android:title="#string/menu_settings"/>
</menu>
I want to show the search item alwys and the other two in a dropdown, I made the showasaction as "collapseActionView" but am not getting any dropdown. Here's the sample pic of what am expecting. Thanks! :)
I just changed the code and order.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:icon="#drawable/share_ab"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_share_app"
android:icon="#drawable/share_ab"
android:showAsAction="never"
android:title="#string/menu_share_app"/>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/share_ab"
android:showAsAction="never"
android:title="#string/menu_settings"/>
</menu>
If you are having physical menu button (e.g. Nexus S) in your device then the dot line will not show. Even if your AVD emulates a device with has physical menu button then same thing will happen. When you press the Menu button it’ll show up.