Java 如何删除操作栏右上角的设置图标(溢出菜单)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21099386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I remove settings icon (overflow menu) on top-right of action bar?
提问by Paradox
How do I remove the settings icon from the top-right of the action bar? When I emulate on my actual Samsung galaxy s3 phone, it is not there, however, when I emulate on an AVD for the Nexus 7, it appears. Here is the code for my menu:
如何从操作栏的右上角删除设置图标?当我在实际的三星 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>
采纳答案by Adam S
If you mean the three dots, that's called the overflow menu. It exists on devices which do not have a hardware menu button - which your Galaxy S3 has, while the Nexus 7 does not. So on your S3 you press the menu button and get the popup at the bottom, but on the Nexus you press the 3 dots and get the overflow popup dropping down from the action bar. If it wasn't there, how would you be able to access overflow items?
如果您指的是三个点,则称为溢出菜单。它存在于没有硬件菜单按钮的设备上——你的 Galaxy S3 有,而 Nexus 7 没有。因此,在您的 S3 上,您按下菜单按钮并在底部获得弹出窗口,但在 Nexus 上,您按下 3 个点并从操作栏下拉溢出弹出窗口。如果它不存在,您将如何访问溢出项目?
If you'd simply like to remove it altogether, just delete the first <item />
entry in the menu.xml
you posted.
如果您只想完全删除它,只需删除您发布的第一个<item />
条目menu.xml
。
回答by vipul mittal
as android:showAsAction for the following item is set to never this item becomes part of overflow menu. set this to always or ifroom r remove this item and it will work
因为以下项目的 android:showAsAction 设置为从不该项目成为溢出菜单的一部分。将此设置为始终或 ifroom r 删除此项目,它将起作用
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
回答by prajitdas
There are two methods in your "MainActivity" java class. They are called onCreateOptionsMenu and onOptionsItemSelected. These are usually added by IDEs like Eclipse when you use the default settings to create an Activity in your project. The methods look like the ones shown below.
“MainActivity”java 类中有两种方法。它们被称为 onCreateOptionsMenu 和 onOptionsItemSelected。当您使用默认设置在项目中创建活动时,这些通常由 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);
}
These methods create the menu items and insert code for what is to be done when one of the menu items are clicked. Just remove or comment out these two methods and you should see that the menu button will vanish. The XMLs can still have them just in case you want your menu items or menu back.
这些方法创建菜单项并为单击菜单项之一时要执行的操作插入代码。只需删除或注释掉这两个方法,您应该会看到菜单按钮将消失。XML 仍然可以保留它们,以防万一您想要返回菜单项或菜单。