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
Related
I'm new in Android
when i set icon in drawer_menu.xml code then after when i open the
navigation drawer menu it open slowly why?
If any one have answer to this question or ever faced this type of
issues then plz reply to this question.
Here is my drawer_menu.xml code.
<?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/home_id"
android:icon="#drawable/home"
android:title="Home"></item>
<item
android:id="#+id/id_setting"
android:icon="#drawable/setting"
android:title="Settings"></item>
</group>
<item android:title="Others">
<menu>
<item
android:id="#+id/notifications"
android:icon="#drawable/noti"
android:title="Notifications"></item>
<item
android:id="#+id/about_us"
android:icon="#drawable/aboutus"
android:title="About us"></item>
</menu>
</item>
</menu>
What is the size of icon?
use 300*300
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">
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>
I know two ways to show action bar icons. My minimum sdk is 14 and target sdk 19. I am debugging with android 4.2.
First one
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/mPre"
android:icon="#drawable/ic_action_previous_item"
android:showAsAction="always"
android:title="Previous"/>
<item
android:id="#+id/mNext"
android:icon="#drawable/ic_action_next_item"
android:showAsAction="ifRoom"
android:title="Next"/>
<item
android:id="#+id/mShare"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="Share"/>
<item
android:id="#+id/mFb"
android:icon="#drawable/fb"
android:showAsAction="ifRoom"
android:title="Facebook"/>
<item
android:id="#+id/mhelp"
android:icon="#drawable/ic_action_help"
android:showAsAction="ifRoom"
android:title="Help"/>
</menu>
This will show icon dynamically (2 or 3 as consider space of action bar). But problem is, this is not showing extra menu in overflow icon. When I touch my phone menu bar, extra menu will appears, but I want extra menu in overflow icon.
For solution my second code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/mPre"
android:icon="#drawable/ic_action_previous_item"
android:showAsAction="always"
android:title="Previous"/>
<item
android:id="#+id/mNext"
android:icon="#drawable/ic_action_next_item"
android:showAsAction="always"
android:title="Next"/>
<item
android:id="#+id/mMore"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="More">
<menu>
<item
android:id="#+id/mShare"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="Share"/>
<item
android:id="#+id/mFb"
android:icon="#drawable/fb"
android:showAsAction="never"
android:title="Facebook"/>
<item
android:id="#+id/mhelp"
android:icon="#drawable/ic_action_help"
android:showAsAction="never"
android:title="Help"/>
</menu>
</item>
</menu>
The problem of this code this is not really dynamic. I am showing here two icon always and put others icon in overflow icon, this overflow icon is not real overflow icon.
Now what I want?
I want if I have five menu as much as menu will show in action bar and rest of the icons are stored in overflow icon automatically.
I hope you guys get my problem. Please help me. Thanks in advance.
i think you need to use this
android:showAsAction="ifRoom|withText"
the parameter showAsAction decides where the icon is to be shown
refer to this link and the documentation
If I understand correctly, you want the the action bar icons to always show on the overflow? If that's the case, you can try the following:
<item
android:id="#+id/action_settings"
android:title="Test"
app:showAsAction="never" />
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.