How to handle backward compatibility for android menu button

With the intention to get rid of hardware buttons on Android devices, the android menu button has been replaced in honeycomb release 3.0 (API level 11) and later, in favor of virtual touch fields on the screen. However the menu button won’t even be available as a virtual touch field in newer releases as of honeycomb. All those actions of your application, which were implemented in the menu, should be migrated instead to the action bar which is an Android UI item available since API level 11, though as a workaround you can rely on the backward compatibility to emulate the menu button for newer Android releases.

How to control the backward compatibility behaviour

The backward compatibility behaviour of the application is controlled by the <use-sdk> elements in the Android Manifest file of each application, basically by using the android:minSdkVersion and android:targetSdkVersion.

android:minSdkVersion will specify which API level is at least necessary to properly run the application.

android:targetSdkVersion will determine which API level will be assumed on the device to run the application. Whenever the used release is newer then the assumed API level, the framework will might activate compatibility features to support the application nevertheless.

How to activate the menu button emulation

To ensure the menu button to be emulated in Android releases as of 3.0, as a workaround, we have to eventually set both elements to a value less than 11. As a result we will notice a dashed vertical line in the navigation bar on the screen (see image) in Android release 4.x, which assumes the function of the menu button in earlier Android releases.


In Android release 3.x the virtual navigation bar and the emulated menu button look kind of different as shown in the image below.

For example setting the elements to the following values…

<uses-sdk android:minSdkVersion="8" 

… will ensure the application to run on devices with Android release 2.2 and newer. If the Android release is higher than 2.3.3 the Android framework might activate compatibility features to emulate the menu button as described earlier.

Devices with hardware buttons and Android release honeycomb and newer

Actually on all devices which still have the well known hardware buttons (back, home, search and menu) the menu button emulation won’t be enforced by setting the apropiate settings in the Android Manifest file, although the release is higher than specified by android:targetSdkVersion. On these devices (e.g. Google Nexus S) the virtual touch fields won’t appear on the screen, but the usual hardware buttons will still work properly.

Be aware that these settings should be only used as a workaround. The best solution should be to migrate the menu to the action bar element.