I'm trying to show same menu options both in the ActionBar and in the menu options but it shows up only in one of them, is there a simple way to do it?
<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.app.MainActivity" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="always"/>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="always"/>
</menu>
Now the items appear in the action bar.
Changing the app:showAsAction to android:app:showAsAction shows the menu items at the options menu only, any way to make them appear in both menus?
Thanks
Change showAsAction="always" to showAsAction="never" for which you want to display in option menu at bottom...
See showAsAction element in below link for more details...
http://developer.android.com/guide/topics/resources/menu-resource.html
Related
I tried to add an icon for "Create Order" to be displayed on the action bar, but the icon is not being displayed instead on the action bar only 3 dots are being showed and inside them there is written "Create Order".
The following is my xml code:
<?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=".MainActivity">
<item android:id="#+id/action_create_order"
android:title="#string/action_create_order"
android:icon="#drawable/ic_add_black_24dp"
android:orderInCategory="1"
app:showAsAction="always">
</item>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
Use app:showAsAction to ifRoom as below:
<?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/create_order"
android:icon="#drawable/ic_add_black_24dp"
android:title="#string/action_create_order"
app:showAsAction="ifRoom" />
</menu>
Note:
The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar. If you set app:showAsAction="ifRoom" (as in the example code's favorite action), the action is displayed as a button if there is room in the app bar for it; if there is not enough room, excess actions are sent to the overflow menu. If you set app:showAsAction="never" (as in the example code's settings action), the action is always listed in the overflow menu, not displayed in the app bar.
Refer below link for more details:
Add Action Buttons
If you want to show the Icon and the Text "Create Order" you can use:
app:showAsAction="ifRoom|withText"
of course, it can show only, if your view has enough space for these elements.
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
Hi I am developing sample Android application in which I am trying to display menu items in actionbar. But my actionbar always showing overflow menu even if there is only single menu item. It is not showing my menu items image in action bar. I have implemented this in following manner
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.samplechromiapp.MainActivity" >
<item
android:id="#+id/categories"
android:icon="#drawable/navigation_collapse"
android:showAsAction="ifRoom|withText"
android:title="Categories"
android:visible="true"
/>
</menu>
Am I doing anything wrong? Need some help. Thank you.
Try this code and add extra xmlns attribute for your menu and try app:showAsAction instead of android:showAsAction
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/categories"
android:icon="#drawable/navigation_collapse"
android:title="Categories"
app:showAsAction="always"/>
</menu>
I followed the android developers training and
wrote application that should have action bar.
I added two items to the Action Bar:
the first has icon and android:showAsAction="IfRoom"
the second, has only string and android:showAsAction="Never".
main_menu_actions.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.shaniandroid.myfirstapp.MainActivity" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/search_icon"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
However the Action Bar is not displayed!
The items are only displayed when the menu button
is pressed.
I read in earlier answers that the "overflow" button doesn't appear
on 4.3 if a hardware menu button is present - and that is OK for the second item.
But what about the first item - shouldn't it appear with its icon on top of screen?
Notice: I run the app on galaxy S3 4.3.
If you are using AppCompat then you should use app namespace for showAsAction which you have declared. Your main_menu_actions.xml should then look like this:
<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.shaniandroid.myfirstapp.MainActivity" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/search_icon"
android:title="#string/action_search"
app:showAsAction="ifRoom" /> <!--here-->
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never" /> <!--and here-->
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.