Android actionbar always showing overflow menu for menu items in actionbar - android

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>

Related

Hide the top level menu when pop up sub menu is displayed in Android app

Android app has one top level menu named "Organisation" which gets displayed on the click of ellipsis (3 dots).
On touching this menu, pop up submenu gets displayed with top item as Organisation.
I want to hide this top level menu
and
only show 2 items in the sub pop up menu.
"Register Org" and "Change Org" are apps 2 sub popup menu items.
How do I do that? I tried below code which doesn't work.
MenuItem topLevelMenuOrganisation = menuList.findItem(R.id.idMenuOrganisation);
topLevelMenuOrganisation.setVisible(false);
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.example.jayantbhave.menuapps.MainActivity">
<item
android:id="#+id/idMenuOrg"
android:title="Organisation">
<menu>
<item
android:id="#+id/idMenuRegisterOrg"
android:title="Register Org" />
<item
android:id="#+id/idMenuChangeOrg"
android:title="Change Org" />
</menu>
</item>
</menu>
You can remove the "Organisation" item from the menu. Write your menu as following:
<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.jayantbhave.menuapps.MainActivity">
<item
android:id="#+id/idMenuRegisterOrg"
android:title="Register Org" />
<item
android:id="#+id/idMenuChangeOrg"
android:title="Change Org" />
</menu>
Hope it helps!

I cannot get icons on the action bar

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.

Actionbar sherlock items not showing up

I followed the steps according to the their official website. Still it doesn't show up items on the actionbar. I also updated the theme name on manifest file.
Any help?
Your question is so general but I think you need to change your menu xmls. They are under res/menu. If the name of your class is main, then menu should be in menu_main.xml. You should change app:showAsAction to ifRoom or always.
<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_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="always" android:icon="#drawable/ic_action_important" />
</menu>

app:showAsAction="always|withText" not showing text

I have an action bar with the follwing menu:
<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="br.com.putzbati2.PrincipalActivity" >
<item android:id="#+id/action_mensagem"
android:title="Mensagem"
android:icon="#drawable/barra_superior_envelope"
android:showAsAction="always|withText" />
<item android:id="#+id/action_carro"
android:icon="#drawable/barra_superior_carro"
app:showAsAction="always"
android:title="Meus Carros"/>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
But the withText doesnt work. It shows only the icon.
I've already try to use android:showAsAction instead of app:showAsAction and when I do this, it doesnt show the icon neither the text. Does any one know how to help me?
I've found this solution, but as I said, it doesnt work for me
app:showAsAction ifRoom is not working on appcompat action bar
You can use like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_mensagem"
android:title="#string/id_item_mensagem"
android:icon="#drawable/id_item_mensagem"
android:showAsAction="always|withText" />
<!-- ... another items -->
</menu>
'always|withText' will work if there is enough room, otherwise it will only place icon! You are using so much items with text, probably you don't have room. So you will see only the icon.
You can check it if you rotate your application to landscape.

Create ActionBar and options menu in same activity

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

Categories

Resources