开发者

How I hide the menu button for one activity

There is an activity which has no menu item. So I开发者_StackOverflow社区 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:

<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" (i.e. your "preferred" version - in my case, that's 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.

If you make targetSdkVersion post-Honeycomb, then the menu button will only be shown if you actually have menu items defined.


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]

[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.

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


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.

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.

If you are trying this on some non-compliant Android device that does its own soft menu button, you are out of luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜