简体   繁体   English

我如何隐藏一项活动的菜单按钮

[英]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.默认情况下, targetSdkVersionminSdkVersion相同,如果你离开那个 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.

相关问题 如何在单个活动中从菜单(ActionBar中的按钮)隐藏一个项目(按钮)并显示另一个项目(按钮) - How to hide one item(Button) and show another item(Button) from menu (Buttons in ActionBar) in single Activity 在活动菜单中recyclerview中隐藏按钮,菜单不起作用 - Hide button in recyclerview from activity with menu not working 如何隐藏活动? - How can I hide an Activity? 从菜单项中选择一项是要进行的活动,我该如何在android中进行直接活动 - select from menu item one is activity to go, how can i go direct activity in android 如何在一个活动中创建按钮以修改其他活动中的组件 - How can I make a button in one activity to modify components in other 如何将按钮设置为从一个活动隐藏到另一个活动? - How can I set a button to invisible from one activity to another? 如何启用我活动下方的菜单按钮 - how to enable menu button below my activity Android-如何在操作栏中隐藏菜单按钮 - Android - How to hide the Menu Button in Action Bar 如何从不带工具栏或菜单按钮的活动中打开菜单 - How to Open Menu from Activity w/o toolbar or menu button 如何隐藏溢出菜单,通过单击硬件菜单按钮使其保持活动状态 - How to hide the overflow menu leaving it active by clicking hardware menu button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM