[英]How I hide the menu button for one activity
There is an activity which has no menu item.有一个没有菜单项的活动。 So I want to hide the menu button.
所以我想隐藏菜单按钮。 Is there any way to achieve that?
有没有办法做到这一点? Thanks
谢谢
I figured out how this can be done.我想出了如何做到这一点。 In your AndroidManifest.xml, you need to specify something like the following:
在您的 AndroidManifest.xml 中,您需要指定如下内容:
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="14" />
Basically, minSdkVersion
is the minimum Android SDK version that you application supports (in my case, 2.2) and targetSdkVersion
is the version you're "targetting" (ie your "preferred" version - in my case, that's 4.0)基本上,
minSdkVersion
是您的应用程序支持的最低 Android SDK 版本(在我的情况下,2.2)和targetSdkVersion
是您“定位”的版本(即您的“首选”版本 - 在我的情况下,即 4.0)
By default, targetSdkVersion
is the same as minSdkVersion
, and if you leave that pre-Honeycomb, you're basically telling Android that your app is "legacy" and it'll always show the menu button.默认情况下,
targetSdkVersion
与minSdkVersion
相同,如果你离开那个 pre-Honeycomb,你基本上是在告诉 Android 你的应用是“旧的”,它总是会显示菜单按钮。
If you make targetSdkVersion
post-Honeycomb, then the menu button will only be shown if you actually have menu items defined.如果您将
targetSdkVersion
在 Honeycomb 之后,则只有在您确实定义了菜单项时才会显示菜单按钮。
You can do using the onPrepareOptionsMenu, where you set the menu item that you want to show to user,[http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29][1]您可以使用 onPrepareOptionsMenu,在其中设置要向用户显示的菜单项,[http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu% 29][1]
[1]: http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29 . [1]: http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29 。 Do not inflate using the xml just do it manually.
不要使用 xml 充气,只需手动进行即可。
Thank you.谢谢你。
Try this to include in your code so that the menu items are not automatically visible when you start the activity.尝试将此包含在您的代码中,以便在您启动活动时菜单项不会自动可见。
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
//add the menu items here
return true;
}
By writing like this the menu items are visible only when you click on the menu button of the android smartphone通过这样写,菜单项只有在您单击 android 智能手机的菜单按钮时才可见
So I want to hide the menu button
所以我想隐藏菜单按钮
On the vast majority of Android devices, the "menu button" is a physical thing, and cannot be hidden, any more than I can hide a mountain or a molehill.在绝大多数 Android 设备上,“菜单按钮”是一个物理的东西,无法隐藏,就像我无法隐藏一座山或一座小山丘一样。
On Honeycomb, if you do not define an options menu, you should not get the "overflow" button in the upper right corner, in the action bar.在 Honeycomb 上,如果您没有定义选项菜单,则不应在操作栏中的右上角获得“溢出”按钮。
If you are trying this on some non-compliant Android device that does its own soft menu button, you are out of luck.如果你在一些不兼容的 Android 设备上尝试这个,它有自己的软菜单按钮,你就不走运了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.