can someone explain why the 2nd item is not being added to the overflow menu in the actionbar? The settings displays correctly, and profile displays if I set the showAsAction to always, but I would rather have profile appear in the overflow menu.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Molo="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings"
Molo:showAsAction="always" />
<item android:id="#+id/action_profile"
android:title="#string/action_profile"
android:icon="#drawable/user"
Molo:showAsAction="never"/>
</menu>
Add android:showAsAction mapped to the same value as Molo:showAsAction, as that should help on newer devices.
just removed the Molo:showAsAction="never" ,Try this..
<?xml version="1.0" encoding="utf-8"?>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings"
Molo:showAsAction="always" />
<item android:id="#+id/action_profile"
android:title="#string/action_profile"
android:icon="#drawable/user" />
Related
I am using v7 Support library and using app namespace in the menu_main.xml file. Even then, the action is never displayed in the action bar but in the overflow bar. This happens even when I use app:showAsAction="always"
menu_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="#+id/action_create_order"
android:title="#string/action_create_order"
android:orderInCategory="1"
app:showAsAction="always"
android:icon="#drawable/add_box_black_icon"
/>
</menu>
The order of the items is important - swap the create order and settings if you want to achieve your original idea.
I need to trigger a function on clicking the menu icon, and I don't need to show any items inside the menu. When I tries to avoid all the items inside the menu tag, the whole icon itself gets invisible. So how could I display only the menu icon and hide its sub 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">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_camera"
android:title="Settings"
app:showAsAction="never" />
//removing the above item removes the whole menu title icon.
</menu>
you need to change app:showAsAction="always", 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/action_settings"
android:icon="#drawable/ic_menu_camera"
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="always" />
</menu >
check this https://developer.android.com/guide/topics/resources/menu-resource.html
Either use visible = false
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_camera"
android:title="Settings"
android:visible=false
app:showAsAction="never" />
Or Use a Toolbar inside which add a Menu icon and set onCLickListener().
so i made my own toolbar with a menu and i am infalting it:
toolbarBottom.inflateMenu (R.menu.user_interaction);
and this is the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res/android">
<item app:title="Edit"
app:id="#+id/post"
app:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item app:id="#+id/menu_share"
app:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
app:title="Undo" />
<item app:id="#+id/test"
app:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
app:title="Redo" />
</menu>
what i get now is the 3 android option dots on the right side of my bar. If i press it my 3 menuĀ“s appear. What i want is the 3 menu items to appear on the bar itself witht he 3 icon drawables.
Where is my mistake? Did i forgot something? :O
ok i solved it like this:
<?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:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>
It should be:
<?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:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>
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 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.