简体   繁体   English

按下菜单按钮时的Android菜单

[英]Android Menu when menu button is pressed

I would like to create a menu to appear on the screen when the Menu button is pressed. 我想创建一个菜单,当按下“菜单”按钮时出现在屏幕上。 I've implemented it and it appears in the bottom of the page but not where I would like. 我已经实现了它,它显示在页面底部,但不在我想要的位置。 My code is here with an image of what I am trying to achieve. 我的代码在这里,上面有我要实现的图像。

main.xml main.xml中

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/expandall"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="Expand All"/>


<item
    android:id="@+id/collapseall"
    android:orderInCategory="100"
    android:showAsAction="withText"
    android:title="Collapse All"/>


<item
    android:id="@+id/myprofile"
    android:orderInCategory="100"
    android:showAsAction="withText"
    android:title="My Profile"/>

<item
    android:id="@+id/signout"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="Sign Out"/>

public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.collapseall:
    // Single menu item is selected do something

    collapseAll();

    return true;

case R.id.expandall:

    expandAll();

    return true;
  }
}

My desired Menu: 我想要的菜单:

在此处输入图片说明

My Current Menu 我当前的菜单

在此处输入图片说明

尝试从所有项目中删除android:orderInCategory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM