The correct solution is to use an ActionBar , but some hacks may appear to display the overflow menu.
In particular, there is a hidden window flag FLAG_NEEDS_MENU_KEY , which you can get through reflection. Here's a snippet of code (from this blog ):
public static void addLegacyOverflowButton(Window window) { if (window.peekDecorView() == null) { throw new RuntimeException("Must call addLegacyOverflowButton() after setContentView()"); } try { window.addFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null)); } catch (NoSuchFieldException e) {
I tested this on several Nexus devices and it works. Comments on the blog say that there are devices in which it does not work. Use with caution. And use the ActionBar , really.
source share