Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing the menu button on ICS while keeping android:targetSdkVersion to be 14

I have an existing app with a full screen viewer that uses the menu button to show options. I've set the android:targetSdkVersion to be 14 to have the entire app theme look like a native ICS APP.

The problem is that when setting the Activity style to be full screen, I don't have the menu button, and if I show the ActionBar, is takes app too much screen space just to display a menu.

Is there any way of keeping the regular menu button while in full screen on ICS?

like image 952
Oren Bengigi Avatar asked Oct 09 '22 05:10

Oren Bengigi


2 Answers

I suppose there is no way to show only small part of action bar of ICS - at least it will look strange. The best way for you is create somewhere in your app "menu button". If you want to hide this button for phones with hardware menu button there is option to check SDK version: android.os.Build.VERSION.SDK_INT

like image 55
Jin35 Avatar answered Oct 13 '22 10:10

Jin35


There is a way, if you're comfortable with hackiness and reflection. Daniel Lew mentions it in his blog. He notes, appropriately, that this really isn't meant to be used with production code. The Android developers may take away this ability in the future.

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) {
    // Ignore since this field won't exist in most versions of Android
  }
  catch (IllegalAccessException e) {
    Log.w(TAG, "Could not access FLAG_NEEDS_MENU_KEY in addLegacyOverflowButton()", e);
  }
}
like image 22
dgmltn Avatar answered Oct 13 '22 11:10

dgmltn