【问题标题】:How do I remove settings icon (overflow menu) on top-right of action bar?如何删除操作栏右上角的设置图标(溢出菜单)?
【发布时间】:2014-01-13 19:10:52
【问题描述】:

如何删除操作栏右上角的设置图标?当我在我的实际三星 Galaxy s3 手机上进行仿真时,它不存在,但是,当我在 Nexus 7 的 AVD 上仿真时,它出现了。这是我的菜单的代码:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    <item
        android:id="@+id/main_menu_actionbutton"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:title="@string/Menu"/>
</menu>

【问题讨论】:

  • 好吧,删除那个项目

标签: java android android-actionbar


【解决方案1】:

如果您指的是三个点,则称为溢出菜单。它存在于没有硬件菜单按钮的设备上——你的 Galaxy S3 有,而 Nexus 7 没有。因此,在您的 S3 上,您按下菜单按钮并在底部弹出弹出窗口,但在 Nexus 上,您按下 3 个点并获得从操作栏下拉的溢出弹出窗口。如果它不存在,您将如何访问溢出项?

如果您只是想完全删除它,只需删除您发布的 menu.xml 中的第一个 &lt;item /&gt; 条目即可。

【讨论】:

  • 有什么例子请帮帮我
【解决方案2】:

“MainActivity”java 类中有两种方法。它们被称为 onCreateOptionsMenu 和 onOptionsItemSelected。当您使用默认设置在项目中创建 Activity 时,这些通常由 Eclipse 等 IDE 添加。这些方法如下所示。

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

这些方法创建菜单项并插入代码,用于在单击菜单项之一时执行的操作。只需删除或注释掉这两种方法,您应该会看到菜单按钮将消失。 XMLs 仍然可以拥有它们,以防万一您想要恢复您的菜单项或菜单。

【讨论】:

    【解决方案3】:

    因为以下项目的 android:showAsAction 设置为从不该项目成为溢出菜单的一部分。 将此设置为始终或 ifroom r 删除此项目,它将起作用

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多