【问题标题】:Adding menu(overflow) to the customize title bar in android将菜单(溢出)添加到android中的自定义标题栏
【发布时间】:2014-03-05 16:55:03
【问题描述】:

我在我的活动中创建了一个自定义标题栏。

现在我想在我的自定义标题栏中添加如下图所示的菜单(溢出)。

我指的是tutorial。但是,它对我不起作用。我只想要包含 3 个项目的溢出菜单。

这是我的代码。

Activity.java

 public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menutit, menu);

            return super.onCreateOptionsMenu(menu);
        }

MenuTit.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Search / will display always -->
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/yellow"
        android:showAsAction="always"
        android:title="action_search"/>

    <!-- Location Found -->
    <item
        android:id="@+id/action_location_found"
        android:icon="@drawable/yellow"
        android:showAsAction="always"
        android:title="action_location_found"/>

    <!-- More -->
    <item
        android:id="@+id/a_More"
        android:icon="@drawable/yellow"
        android:showAsAction="always"
        android:title="More">
        <menu>

            <!-- Refresh -->
            <item
                android:id="@+id/action_refresh"
                android:icon="@drawable/brown"
                android:showAsAction="never"
                android:title="action_refresh"/>

            <!-- Help -->
            <item
                android:id="@+id/action_help"
                android:icon="@drawable/brown"
                android:showAsAction="never"
                android:title="action_help"/>

            <!-- Check updates -->
            <item
                android:id="@+id/action_check_updates"
                android:icon="@drawable/brown"
                android:showAsAction="never"
                android:title="action_check_updates"/>
        </menu>
    </item>

</menu>

任何人都可以告诉我是否需要做一些特别的事情才能将菜单项添加到自定义标题栏?

【问题讨论】:

  • 哪个部分不工作...您是否能够让其他(非溢出)操作项出现在 actionBar 中?
  • 你使用appcompat还是sherlockactionbar
  • @Fllo 不,我没有使用 appcompat 或 sherlockactionbar。
  • @es0329 我只想要菜单但它不起作用我没有使用操作栏我只想要菜单所以我想我不需要操作栏。

标签: android android-layout


【解决方案1】:

您需要在菜单 xml 中添加项目,并使用 showAsAction = never 或 ifRoom。

【讨论】:

  • 我这样做了,但它仍然无法正常工作。它没有给我任何错误,但它没有显示菜单。
  • 如果按下菜单按钮会怎样?是否有一个选项菜单来显示其余缺失的项目?
  • 在原始帖子中添加了代码。菜单按钮根本不显示。
  • 我的意思是设备的硬件菜单按钮
  • 是的,它在活动底部显示设置。
猜你喜欢
  • 2018-05-28
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多