19

I have an app that uses android:minSdkVersion="7" and android:targetSdkVersion="10". Is it possible to hide the option menu button that is on screen on ICS (api level 14)?

Some of the activities may use the option menu, but not all. It would be great to show/hide the option menu button to make it more intuitive for the user where he/she can expect to find more functionality.

Roy Solberg
  • 18,133
  • 12
  • 49
  • 76

3 Answers3

4

How about increasing targetSdkVersion to 11 (or even 15)? According to the Android CDD that cut off for legacy Menu button is version > 10.

user1076637
  • 768
  • 5
  • 15
  • 1
    Setting targetSdkVersion to 14 or higher helped (tested on Galaxy Nexus, running 4.0.4). However, increasing targetSdkVersion to 14 brought some artifacts to view animation (became less smooth). So, had to refuse this solution in my project. – Coryffaeus Aug 03 '12 at 08:14
0

If it is your button then you can check the version of Android and hide this button according to the version (http://developer.android.com/reference/android/os/Build.VERSION.html)

Yury
  • 20,618
  • 7
  • 58
  • 86
  • This is the [system's option menu button](http://developer.android.com/guide/topics/ui/menus.html#options-menu). I'm asking about ICS because this button has been a hardware feature in the earlier versions. – Roy Solberg Dec 22 '11 at 09:30
  • I've somewhere read that you cannot hide the panel with buttons in ICS. – Yury Dec 22 '11 at 09:50
  • Yes, that is true. But the Galaxy Nexus (running ICS) hides the option menu button on the home screen (and still displays back, home, task switcher). So I was hoping to be able to hide it myself when there's no use for it. – Roy Solberg Dec 22 '11 at 10:03
-1

Return false from onCreateOptionsMenu(Menu) and it won't show the menu button on ICS.

Hounshell
  • 5,321
  • 4
  • 34
  • 51
  • 6
    I tried out this out now. It does **not** matter what this method returns, but the android:targetSdkVersion affected it showing or not. If I don't use a targetSdkVersion, or if it set to 13 or lower the system menu button is displayed no matter what. If I set it to 14 or higher it's gone no matter what. I guess the last bit must be a [bug](http://stackoverflow.com/questions/8346064/options-menu-not-showing-in-ics-using-compatibility-library). Anyways, I would like to keep targetSdkVersion at 10, so maybe the answer is 'no' to my original question. – Roy Solberg Dec 22 '11 at 11:59
  • Are you turning meny items on and off? It's only called once so if you need to enable/disable dynamically there's a different method. – Hounshell Dec 22 '11 at 14:59
  • 1
    This is the first time the activity is created. And it's in an activity where I don't want to that the menu button to be visible as it doesn't give the user any options. – Roy Solberg Dec 22 '11 at 15:45
  • This doesn't work reliably, the only sure-fired way is to set the target SDK version to 11 or up. – Tom Jun 30 '12 at 20:31
  • Works if set targetSDKVersion to 14. See http://android-developers.blogspot.de/2012/01/say-goodbye-to-menu-button.html – Eugene Petrenko Jul 02 '12 at 20:44
  • When I set the target SDK to be version 14, the menu button is not shown regardless of the return value of onPrepareOptionsMenu since sdk 14 should not have a menu button – ekatz Jul 16 '12 at 22:01
  • You're right. I've been a fool. A fully prudent foolish fool. If only I had had the foresight to mention that this applied to ICS (actually Honeycomb and up) so that I wouldn't be feeling so shameful right now. – Hounshell Dec 20 '13 at 18:46