我怎样才能创建android菜单

时间:2014-04-12 16:43:11

标签: android

我想像这个菜单一样创建菜单

因为当我在链接中确实喜欢它时,它会显示在顶部,我希望它在链接中显示

this is my menu

这是我的java文件查看这些代码,我正在等待答案

@Override
        public boolean onCreateOptionsMenu(Menu menu)
        {
            MenuInflater menuInflater = getMenuInflater();
            menuInflater.inflate(R.layout.menu, menu);
            return true;
        }
        @Override
        public boolean onOptionsItemSelected(MenuItem item)
        {

            switch (item.getItemId())
            {
            case R.id.undo:

                Toast.makeText(Map.this, "Bookmark is Selected", Toast.LENGTH_SHORT).show();
                return true;

            case R.id.track:
                Toast.makeText(Map.this, "Save is Selected", Toast.LENGTH_SHORT).show();
                return true;

            case R.id.Hyper:
                Toast.makeText(Map.this, "Search is Selected", Toast.LENGTH_SHORT).show();
                return true;

            default:
                return super.onOptionsItemSelected(item);
            }
        }   

这是我的XML文件     

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item 
          android:id="@+id/undo"
          android:icon="@drawable/icon_bookmark"
          android:title="Bookmark" />

    <item android:id="@+id/track"
          android:icon="@drawable/icon_save"
          android:title="Save" />

    <item android:id="@+id/Hyper"
          android:icon="@drawable/icon_search"
          android:title="Search" />
</menu>

1 个答案:

答案 0 :(得分:3)

您正在寻找Android操作栏菜单: 看看:http://developer.android.com/guide/topics/ui/actionbar.html