MenuPopupHelper cannot be used without an anchor - android

I want add PopupMenu to my MenuItem.
Menu.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/date"
app:showAsAction="ifRoom|withText"
android:title="Date"
android:visible="true"/>
<item
android:id="#+id/category"
app:showAsAction="ifRoom|withText"
android:title="Category"
android:visible="true"/>
</menu>
When I click on MenuItem I call this code:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.filter_action) {
showPopup(item.getActionView());
}
return super.onOptionsItemSelected(item);
}
private void showPopup(View v) {
PopupMenu popup = new PopupMenu(getActivity(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.filter_billing_menu, popup.getMenu());
popup.show();
}
And I get this exception:
java.lang.IllegalStateException: MenuPopupHelper cannot be used without an anchor
How I can fix it?

I'm reading "internet" and I try this code:
showPopu(getActivity().findViewById(R.id.filter_action));
Instead
showPopup(item.getActionView());
It's works for me

I believe a better (and simpler) approach in this case would be to define a submenu instead of creating a PopupMenu.
For example:
<item android:id="#+id/menu"
android:title="menu" >
<menu>
<item android:id="#+id/item_in_submenu_1"
android:title="subitem1" />
<item android:id="#+id/item_in_submenu_2"
android:title="subitem2" />
</menu>
</item>

My problem was that I had
<item android:id="#+id/menu_entry_to_show_popupmenu"
app:showAsAction="ifRoom" />
and what I needed is
<item android:id="#+id/menu_entry_to_show_popupmenu"
app:showAsAction="always" />
showAsAction="always" is needed. A menu entry hidden in the three dots (overflow menu) can't have a popupmenu anchored to it.
My full popupmenu setup function begins like this:
PopupMenu popup = new PopupMenu(getActivity(), getActivity().findViewById(R.id.menu_filter));
popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
[...]
popup.show();
}

Change your this code:
app:showAsAction="ifRoom|withText"
to this:
android:showAsAction="ifRoom|withText"

Related

Add right margin to the options menu sub-items

Currently, my options menu is aligned to the end of the screen. I want to give it a margin, something like android:layout_marginEnd = "20dp". How can I achieve this?
My options menu:
<?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/menu_items"
android:icon="#drawable/menu_icon"
app:showAsAction="always">
<menu>
<group android:id="#+id/item1">
<item
android:id="#+id/download"
android:icon="#drawable/download_icon"
android:title="Download"></item>
</group>
<group android:id="#+id/item2">
<item
android:id="#+id/invite"
android:icon="#drawable/invite_icon"
android:title="Invite"></item>
</group>
</menu>
</item>
</menu>
My Custom Toolbar:
<androidx.appcompat.widget.Toolbar
android:id="#+id/menu_toolbar"
app:popupTheme="#style/ThemeOverlay.MyTheme"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#id/greetText"> <!--assume it comes somewhere in the centre due to this-->
</androidx.appcompat.widget.Toolbar>
My Theme for menu items:
<style name="ThemeOverlay.MyTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColor">#color/dimGray</item>
<item name="android:textSize">14sp</item>
<item name="android:layout_marginEnd">20dp</item> <!-- doesn't work-->
<item name="android:fontFamily">#font/quicksand_medium</item>
<item name="android:background">#drawable/options_menu_background</item>
</style>
Here is the image of my problem. It shows how the end of the menu and the screen are aligned. I want space/margin between these two.
This is an interesting problem. I tried with many things found on the internet, but nothing works. I tried setting the actionOverflowMenuStyle with dropDownHorizontalOffset attribute which does not work either. Finally, I ended up getting a PopupMenu which works just fine. Here is the implementation.
Get your initial menu shorter with a single item which will open up the popup menu as a submenu.
<?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/menu_items"
android:icon="#drawable/ic_close_swipe"
android:title="#string/app_name"
app:showAsAction="always" />
</menu>
Then create another menu, in your /res/menu/ folder, named popup_menu.xml like the following.
<?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/menu_items"
android:icon="#drawable/ic_close_swipe"
android:title="#string/app_name"
app:showAsAction="always" />
</menu>
Now in your MainActivity, just add the following functions to handle the click action of the menu button and the popup menu.
public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = findViewById(R.id.menu_toolbar);
setSupportActionBar(myToolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_items:
showPopupMenu();
return true;
default:
return false;
}
}
public void showPopupMenu() {
PopupMenu popup = new PopupMenu(this, findViewById(R.id.menu_items));
popup.setOnMenuItemClickListener(this);
popup.inflate(R.menu.popup_menu);
popup.setGravity(Gravity.END);
Object menuHelper;
Class[] argTypes;
try {
Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
fMenuHelper.setAccessible(true);
menuHelper = fMenuHelper.get(popup);
argTypes = new Class[]{boolean.class};
menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
} catch (Exception e) {
e.printStackTrace();
}
popup.show();
}
#Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.invite:
Toast.makeText(this, "Invite", Toast.LENGTH_LONG).show();
return true;
case R.id.download:
Toast.makeText(this, "Download", Toast.LENGTH_LONG).show();
return true;
default:
return false;
}
}
}
I put the working code in this Github Branch. You might consider cloning from that branch and run the application to check if that suffices your expectation.
Hope that helps!

¿Change text color main menu android?

I want to change the color of the text of an item that groups a menu.
The xml file:
<?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/nav_mi_cuenta"
android:icon="#mipmap/ic_mi_cuenta"
android:title="#string/mi_cuenta" />
</group>
<item android:title="#string/herramientas">
<menu>
<item
android:id="#+id/nav_configuracion"
android:icon="#mipmap/ic_config"
android:title="#string/configuraci_n" />
</menu>
</item>
</menu>
I wnat to change text color of:
<item android:title="#string/herramientas">
As you can see, Herramientas comes out in black and as the background is also black it barely looks. I can not find any property to change it. The color of the item 'Mis datos' and 'Configuración' change it programmatically as follows from an external json file of a server:
colorElegido = getParseColor(json.getString("colorMenuLateral"));
navigationView.setBackgroundColor(colorElegido);
colorElegido = getParseColor(json.getString("colorFuenteMenuLateral"));
ColorStateList colorList = getColorList(colorElegido);
navigationView.setItemTextColor(colorList);
The following code will workout,
menu.xml
<?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/nav_mi_cuenta"
android:icon="#mipmap/ic_mi_cuenta"
android:title="#string/mi_cuenta" />
</group>
<item
android:id="#+id/herramientas"
android:title="#string/herramientas">
<menu>
<item
android:id="#+id/nav_configuracion"
android:icon="#mipmap/ic_config"
android:title="#string/configuraci_n" />
</menu>
</item>
</menu>
Add this in your styles,
<style name="TextAppearance44">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">20sp</item>
</style>
<style name="NavigationDrawerStyle">
<item name="android:textSize">16sp</item><!-- text size in menu-->
<item name="android:textColor">#880ACE0A</item>
<item name="itemTextColor">#880ACE0A</item>
</style>
And in your activity,
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
Menu menu = navigationView.getMenu();
MenuItem tools= menu.findItem(R.id.herramientas);
SpannableString s = new SpannableString(tools.getTitle());
s.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance44), 0, s.length(), 0);
tools.setTitle(s);
navigationView.setNavigationItemSelectedListener(this);
Change according to you,
And other text color change you can use like in your xml file,
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
style="#style/NavigationDrawerStyle"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
to make a custom popup make an ImageView in toolbar
private ImageView setting;
public void menuOptions() {
PopupMenu popup = new PopupMenu(MainActivity.this, setting);
// Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.menu_main, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.button1:
return (true);
case R.id.button2:
// block contacts
return (true);
}
return true;
}
});
popup.show(); //showing popup menu
}
on Button click call above function
menuOptions();
in the layout you inflate menu_main.xml, make your desired view.

How to display submenu from PopupMenu without Dismissing Android

I have Java show popup menu function and xml below It work, but I want to display both Min menu and sub menu when user click on main Item.
For example When user Click on Price display child of price, and don't hide the main like price or type of product..., and if click type of product display child of type of product but don't hide main.
Here the result I expect to be.
Show popup menu java
//Filter Menu
public void showPopupMenu(View view) {
// inflate menu
android.widget.PopupMenu popup = new PopupMenu(getApplicationContext(), view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.dailydeal_filter, popup.getMenu());
//popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
popup.show();
}
Here is my xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/category"
android:title="Price">
<menu>
<item android:title="Price From 10-100"></item>
<item android:title="Price From 100-200"></item>
<item android:title="Price From 200-300"></item>
<item android:title="Price Higher then 300"></item>
</menu>
</item>
<item android:id="#+id/type_product"
android:title="Type Product">
<menu>
<item android:title="Buy Sale"></item>
<item android:title="Business Directory"></item>
</menu>
</item>
</menu>

Popup menu on click of a button in action Bar

I am trying to implement an action bar in which one of the buttons on click shows a popup menu.
Here's the menu. XML (menu items in the action bar)
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/search"
android:icon="#drawable/ic_action_search"
android:orderInCategory="0"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/refresh"
android:icon="#drawable/ic_action_refresh"
android:orderInCategory="1"
android:showAsAction="always"
android:title="#string/menu_refresh"/>
<Item
android:id="#+id/popup"
android:icon="#drawable/ic_action_search"
android:onClick="showPopup"
android:orderInCategory="1"
android:showAsAction="always"
android:title="#string/menu_search" />
I wish to show a popup menu on the click of the item having id "#+id/popup".
here is the XML for the popup menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/item1"
android:icon="#drawable/ic_action_search"
android:orderInCategory="0"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/item2"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
android:showAsAction="always"
android:title="#string/menu_search"/>
here is the onClick method for the button
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.overflow, popup.getMenu());
popup.show();
}
And the problem is that no popup shows up on click of that button. Need help folks.
I found this here: http://developer.android.com/guide/topics/ui/menus.html
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/selectImg"
android:icon="#android:drawable/ic_dialog_dialer"
android:showAsAction="always">
<menu>
<item android:id="#+id/top"
android:title="#string/topimg"/>
<item android:id="#+id/bottom"
android:title="#string/botimg" />
</menu>
</item>
</menu>
You can put a menu within a menu to present sub-menus when the item is clicked. Then, in Java, you can use the same methods as usual.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
// View v = findViewById(R.id.f);
switch (item.getItemId()) {
case R.id.top:
//action
return true;
default:
return super.onOptionsItemSelected(item);
}
}
The id of 'top' in the xml is still recognized even though it is a sub menu. This worked for me and it looks just like the popup menu.
Hi every one, that's my own solution : i created the showPopup method, and then i called it in the onOptionsItemSelected like this :
public void showPopup(){
View menuItemView = findViewById(R.id.menu_save);
PopupMenu popup = new PopupMenu(getActivity(), menuItemView);
MenuInflater inflate = popup.getMenuInflater();
inflate.inflate(R.menu.popup, popup.getMenu());
popup.show();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_save:
showPopup();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
popup.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/decon"
android:showAsAction="ifRoom"
android:title="#string/decon"/>
<item
android:id="#+id/mRes"
android:showAsAction="ifRoom"
android:title="#string/mesRes"/>
</menu>
main.xml => it's called onCreateOptionsMenu
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_save"
android:enabled="true"
android:icon="#drawable/action_save"
android:showAsAction="ifRoom|withText"
android:title="#string/action_save"
android:visible="true"/>
</menu>
Finally i
implements PopupMenu.OnMenuItemClickListener to #Override onMenuItemClick method.
As the popup menu is a MENU, you have to handle this by implementing the "onOptionsItemSelected". You'll be able to say what to do for each menu option. It will replace the "onClick" option you defined and will be called automatically.
Try to change 'this' to getActivity().
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(getActivity(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.overflow, popup.getMenu());
popup.show();
}
Hope it helps..!!
I found a solution to this. Instead to using the menu XML to inflate the popup menu, I made a XML layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#8b8989"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:id="#+id/menuItem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="#string/menu1" />
<TextView
android:id="#+id/menuItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="#string/menu2" />
<TextView
android:id="#+id/menuItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="#string/menu3" />
</LinearLayout>
and i changed the onClick method
public void showPopup(View v) {
LayoutInflater inflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(inflater.inflate(
R.layout.overflow_layout, null, false), 300, 400, true);
pw.showAtLocation(findViewById(R.id.container), Gravity.CENTER, 0,
0);
}
This solved the issue
android:onClick="popup"
may be you should change it to android:onClick="showPopup"?

Android adding a submenu to a menuItem, where is addSubMenu()?

I want to add a submenu inside my OptionsMenu to a menuItem, programatically according to my parameters. I've checked "MenuItem" in android sdk and there is no addSubMenu() method!, although you can find "hasSubMenu()" and "getSubMenu".
Was thinking on doing this in onCreateOptionsMenu:
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem mi = menu.getItem(MYITEMID); // << this is defined in my XML optionsMenu
SubMenu subm = mi.addSubMenu(0,1,0,"Map 1"); // no addSubMenu() method!!!???
....
How do I create a submenu inside a menuitem in code?
Sometimes Android weirdness is really amazing (and amusing..). I solved it this way:
a) Define in XML a submenu placeholder like this:
<item android:visible="true" android:id="#+id/m_area"
android:titleCondensed="Areas"
android:title="Areas"
android:icon="#drawable/restaur"
android:enabled="true">
<menu>
<item android:id="#+id/item1" android:title="Placeholder"></item>
</menu>
</item>
b) Get sub menu item in OnCreateOptionsMenu, clear it and add my submenu items, like this:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mapoptions, menu);
int idx=0;
SubMenu subm = menu.getItem(MYITEM_INDEX).getSubMenu(); // get my MenuItem with placeholder submenu
subm.clear(); // delete place holder
while(true)
{
anarea = m_areas.GetArea(idx); // get a new area, return null if no more areas
if(anarea == null)
break;
subm.add(0, SUBAREASID+idx, idx, anarea.GetName()); // id is idx+ my constant
++idx;
}
}
I know this is an old question, but I just came across this problem myself.
The most straightforward way of doing this, seems to be to simply specify the item itself as a submenu, then add to this item.
E.g.:
menu.add(groupId, MENU_VIEW, Menu.NONE, getText(R.string.menu_view));
menu.add(groupId, MENU_EDIT, Menu.NONE, getText(R.string.menu_edit));
SubMenu sub=menu.addSubMenu(groupId, MENU_SORT, Menu.NONE, getText(R.string.menu_sort));
sub.add(groupId, MENU_SORT_BY_NAME, Menu.NONE, getText(R.string.menu_sort_by_name));
sub.add(groupId, MENU_SORT_BY_ADDRESS, Menu.NONE, getText(R.string.menu_sort_by_address));
:
:
Here's a complete answer which builds on the idea of using a placeholder but uses mostly xml to add the submenu.
If you have a menu like so called main_menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="My Menu"
android:id="#+id/my_menu_item">
<!-- A empty SubMenu -->
<menu></menu>
</item>
</menu>
Create another menu sub_menu.xml which will be used in my_menu_item:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="SubMenu One"
android:id="#+id/submenu_one" />
<item android:title="SubMenu Two"
android:id="#+id/submenu_two" />
<item android:title="SubMenu Three"
android:id="#+id/submenu_three" />
</menu>
In your onCreateOptionsMenu:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate your main_menu into the menu
getMenuInflater().inflate(R.menu.main_menu, menu);
// Find the menuItem to add your SubMenu
MenuItem myMenuItem = menu.findItem(R.id.my_menu_item);
// Inflating the sub_menu menu this way, will add its menu items
// to the empty SubMenu you created in the xml
getMenuInflater().inflate(R.menu.sub_menu, myMenuItem.getSubMenu());
}
This solution is nice since the inflater handles most of the work.
The best way to do this is in your xml menu file. You can do this by creating a new menu object inside of an item:
<menu>
<item>
...
<menu>
...
</menu>
...
</item>
</menu>
To provide a comprehensive example of Phil's answer, here is my complete, working XML for a menu with two choices, each of which is a menu with three choices. I intend to add a third menu to the top level ...
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:HTMLCode="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/Examine"
android:title="#string/Examine"
HTMLCode:showAsAction="always">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:HTMLCode="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/load"
android:title="#string/load"
HTMLCode:showAsAction="ifRoom|withText" />
<item android:id="#+id/findfirst"
android:title="#string/findfirst"
HTMLCode:showAsAction="ifRoom|withText" />
<item android:id="#+id/findnext"
android:title="#string/FindNext"
HTMLCode:showAsAction="ifRoom|withText" />
</menu>
</item>
<item android:id="#+id/Redirect"
android:title="#string/Redirect"
HTMLCode:showAsAction="ifRoom|withText">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:HTMLCode="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/getRedirect"
android:title="#string/getRedirect"
HTMLCode:showAsAction="ifRoom|withText" />
<item android:id="#+id/toggleRedirect"
android:title="#string/toggleRedirect"
HTMLCode:showAsAction="ifRoom|withText" />
<item android:id="#+id/copyRedirect"
android:title="#string/copyRedirect"
HTMLCode:showAsAction="ifRoom|withText" />
</menu>
</item>
</menu>
You should consider use a ActionProvider instead.
public class MyActionProvider extends ActionProvider {
private Context mContext;
public MyActionProvider(Context context) {
super(context);
mContext = context;
}
#Override
public View onCreateActionView() {
//LayoutInflater layoutInflater = LayoutInflater.from(mContext);
return null;
}
#Override
public void onPrepareSubMenu(SubMenu subMenu) {
super.onPrepareSubMenu(subMenu);
subMenu.clear();
subMenu.add("menu 1");
subMenu.add("menu 2");
subMenu.add("menu 3");
}
#Override
public boolean hasSubMenu() {
return true;
}
#Override
public boolean onPerformDefaultAction() {
return super.onPerformDefaultAction();
}
}
I would just create the submenu in xml file, and in run time get the submenu from menu object, (using findItem(id) method) and use submenu.setVisible(boolean) to add/remove it on run time.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu1" android:alphabeticShortcut="a"
android:title="Menu No. 1" android:orderInCategory="1" />
<item android:id="#+id/menu2" android:alphabeticShortcut="b"
android:title="Menu No. 2" android:orderInCategory="2">
<menu >
<group android:id="#+id/group2" android:checkableBehavior="single">
<item android:id="#+id/submenu1" android:title="SubMenu No. 1" />
<item android:id="#+id/submenu2" android:title="SubMenu No. 2" />
</group>
</menu>
</item>

Categories

Resources