在 Android 中创建选项菜单 [英] Creating an Options Menu in Android

查看:24
本文介绍了在 Android 中创建选项菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这个链接一样在 android 中创建一个选项菜单http://developer.android.com/guide/topics/ui/menus.html#options-menu

I'm trying to make an option menu in android like this link http://developer.android.com/guide/topics/ui/menus.html#options-menu

但我开发的菜单不显示在页面底部,而是显示在顶部操作栏中.

but my developed menu shows not on bottom of my page but in top action bar.

我的 xml 是下面 my_options_menu.xml

my xml is bellow my_options_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
          android:icon="@drawable/menu_addnew"
          android:title="Νέο"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/help"
          android:icon="@drawable/menu_addnew"
          android:title="Βοήθεια" />
</menu>

我的java代码是

   @Override
    public boolean onCreateOptionsMenu(Menu menu){

         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.my_options_menu, menu);
          return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.new_game:
                //newGame();
                return true;
            case R.id.help:
                //showHelp();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

如何在应用程序底部而不是顶部操作栏上显示菜单?

What can I do to show the menu on bottom of my application and not on top action bar?

我的菜单如下图所示

我想创建如下图所示的菜单

I want create menu like below image

怎么能这样呢?有人可以帮我吗?

How can do that? Can someone help me?

推荐答案

出现在操作菜单中的原因是因为你有 android:showAsAction="ifRoom"在您的 xml 文件中.删除它,你应该很好.

The reason this is showing in the action menu is because you have android:showAsAction="ifRoom" in your xml file. remove that and you should be good.

这篇关于在 Android 中创建选项菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆