How to show overflow menu in action bar - android

I want to display an overflow menu in the action bar , I tried to use a menu in my activity but I'm only getting a popup menu when I click on the menu button on my phone. Is there any way to force that overflow menu for phone with physical buttons ?
Here is my menu file :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom"/>
<item
android:id="#+id/computer"
android:title="computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom"/>
<item
android:id="#+id/gamepad"
android:title="gamepad"
android:icon="#drawable/gamepad"
android:showAsAction="ifRoom"/>
</menu>

You need to go into the menu xml file and make sure it has
android:showAsAction="ifRoom"
and for the icon you use
android:icon="#drawable/yourIcon"
Edit: To make sure you are using the right menu xml, check your activity class that is being run and look for the
onCreateOptionsMenu(Menu menu)
Once you have found that check that the line
getMenuInflater().inflate(R.menu.{0}, menu);
matches your menu xml file, where {0} = your xml file name

Related

Removing the settings menu inflator from Actionbar

I have a action bar set up as this:
When I click on it a settings popup appears like this which when pressed takes me to my apps settings page.
My question is how would I remove the settings popup so that it takes me directly to my settings activity when I press the three dotted button? I tried playing around with code below but it yielded no result.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Goto the menu folder of your project. res>>menu and find the xml file representing the
You have to add the android:showAsAction="always" like below:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu"
android:title="#string/menu_settings_item"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_a" />
</menu>
Use the showAsAction parameter.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu"
android:title="#string/menu_settings_item"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_a" />
</menu>
You can specify that your settings option always appears as a button on the action bar. You don't need the three dots in this case.
For instance, you can specify your action bar menu item like this (notice the "always" value):
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/ic_action_settings"
android:showAsAction="always" />

Can I show icon in overflow menu of Android Toolbar?

Please take in consideration that I'm refering to the Toolbar Widget(Android L/API 21+)
By overflow menu and icons I mean something like this one :
Something more difficult : Is there any way that the icons appear on the RIGHT side of the text?
create a menu in menu, for example: main_activity_actions.xml
and use this code for the toolbar, try it:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:All4One="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/algo"//some id
android:icon="#drawable/kami_nomi_zu_shiru_sekai3" //add the image
android:title="nose"
All4One:showAsAction="always">
<menu>
<item android:id="#+id/WIFI"//option to display on the menu
android:icon="#drawable/nisekoi1"//this is a option of the submenu
android:title="#string/WIFI"/>
<item android:id="#+id/DATOS"
android:icon="#drawable/nisekoi6" //this one also is a option
android:title="#string/DATOS"/>
<item android:id="#+id/BT"
android:icon="#drawable/sao1"
android:title="#string/BT"/>
<item android:id="#+id/NADA"
android:icon="#drawable/nisekoi6" //the same
android:title="#string/NADA"/>
</menu>
</item>
</menu>

Keeping Android Menu Items opened after clickng on one of the items

Can I alter the default behavior of the action bar items menu so the menu doesn't close automatically when any of its items is checked ?
I tried returning false to OnOptionsItemSelected method. Also , I tried to add this line to OnCreateOptionsMenu
menu.PerformIdentifierAction(Resource.Id.fs_action_statusFilter, MenuPerformFlags.PerformNoClose);
You can add a sub menu to an item in your menu by adding a menu element as the child of an item. So the sub menu will open when its parent menu is checked. For example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/file"
android:title="#string/file" >
<!-- "file" submenu -->
<menu>
<item android:id="#+id/create_new"
android:title="#string/create_new" />
</menu>
</item>
</menu>

Android - items in submenu do not appear when clicking on parent menu

Please..please help!
I'm new with android development. After i create an app with simple menu. i click on the parent menu, i don't see the items in the submenu appeared. I don't know why is that. Enyone know this, please teach me.
i use nexus Emulator to show result. (nesux S (4.0", 480 X 800:ddpi)
create menu in the Menu folder -> menu-demo like:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/addnew" android:title="add new">
<menu>
<item android:id="#+id/name" android:title="add name"></item>
<item android:id="#+id/age" android:title="Add age"></item>
</menu>
</item>
<item android:id="#+id/update" android:title="update"></item>
<item android:id="#+id/delete" android:title="delete"></item>
</menu>
i update Mainactivity.java in the src.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_demo, menu);
return true;
}
You're missing android:showAsAction="[property".
You can use a few parameters for showAsAction, such as always, never, and ifRoom.
Add these properties to your code, so for example, a menu item that I always want to appear on the actionbar would be like
<item
android:id="#+id/test"
android:showAsAction="always"
android:title="test" >
</item
For submenus, you basically want the topmost selection shown as an action always and the submenu shown never.

Android - Remove "More actions" button from the ActionBar

I have an ActionBar that should display the action buttons in a custom way. For this I created a custom view and attached it to the ActionBar.
One thing to mention is that I am using a menu.xml resoure file to load the options menu and display them on a smartphone, but do not display them on tablet, instead use a custom view. For this I market every menu item in the xml as: android:showAsAction="never"
Everything looks fine, except one little thing that still remains on the right of the ActionBar - the "More" button.
How can I remove it?
I tried this:
ActionBar bar = activity.getActionBar();
bar.removeAllTabs();
but the "more" button still remains there.
EDIT:
This is my menu.xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_username"
android:icon="#drawable/menu_username"
android:orderInCategory="0"
android:showAsAction="never"
android:title="#string/menu_username">
<menu>
<item
android:id="#+id/menu_logout"
android:title="#string/menu_logout"/>
</menu>
</item>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/menu_settings"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/menu_settings"/>
<item
android:id="#+id/menu_search"
android:icon="#drawable/menu_search"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/menu_search"/>
</menu>
Please note I still want to inflate this menu on a smartphone, but don't want to use it on a tablet.
Setting showAsAction="never" will force an menu item into the overflow. Why not check in onCreateOptionsMenu(...) that the device is a tablet, and if it is just not inflate the menu? Something like this:
public boolean onCreateOptionsMenu(Menu menu) {
if (getResources().getConfiguration().smallestScreenWidthDp >= 600) {
//It's a tablet, don't inflate, only create the manual view
manualMenuCreation();
} else {
getMenuInflater().inflate(R.menu.menu, menu);
}
return true;
}
Don't forget smallestScreenWidthDp is only available in 3.2 or above, so you'll have to take that into consideration.

Categories

Resources