繁体   English   中英

如何删除操作栏右上角的设置图标(溢出菜单)?

[英]How do I remove settings icon (overflow menu) on top-right of action bar?

如何从操作栏的右上角删除设置图标? 当我在我的实际三星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>

如果你的意思是三个点,那就叫做溢出菜单。 它存在于没有硬件菜单按钮的设备上 - 你的Galaxy S3有,而Nexus 7却没有。 所以在你的S3上你按下菜单按钮并在底部弹出窗口,但是在Nexus上你按下3个点并从操作栏中获得溢出弹出窗口。 如果不存在,您将如何访问溢出项?

如果您只是想完全删除它,只需删除您发布的menu.xml的第一个<item />条目。

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

@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);
}

这些方法创建菜单项并插入代码,以便在单击其中一个菜单项时执行操作。 只需删除或注释掉这两种方法,您就会发现菜单按钮会消失。 如果您想要菜单项或菜单,XML仍然可以使用它们。

作为android:showAsAction为以下项目设置为永远不会这个项目成为溢出菜单的一部分。 将此设置为always或ifroom r删除此项目,它将起作用

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

暂无
暂无

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

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