Blocking the Menu Bar from appearing

Hey all

I’ve recently had a couple of people email me a bug that prevents them from playing my game on Android.

It seems that once the game is running, a Menu Bar appears at the bottom of the screen and covers a portion of the game window. A screenshot is below:

I can’t reproduce this with the devices I have for testing, but I noticed that an options button appears next to the switch focus button on my Xperia Z’s on-screen controls. Since the game doesn’t have any options, I was wondering how I can block this entirely?

I’ve tried searching around google, the android SDK and stack overflow, but the terminology makes it difficult to filter out what is relevant. I can’t work out if this is classed as the action bar, menu bar, or something else.

The affected devices (both Moto Droids, but different models) have hardware (not on-screen) controls, but most devices I have used for testing default to using a long press on the home button or switch focus button to access the options instead of requiring an on-screen control.

I’ll keep digging, but if anybody already has a solution to this it would be appreciated.

Cheers

Chris

Ok, so I tried various code fixes and nothing seemed to work. Eventually I found a blog post that gave the reason the menu bar appears, and it turns out the fix is to set the target android platform to 14 (keeping the min version at it’s original setting of 10 means the game should still work on older copies of Android).

I’m not sure what the settings are for the example monogame project but that should sort it.

1 weird thing I found in testing was that on a factory reset HTC device i have, the old settings show the menu bar but the games resolution adapts to that fine. For some reason the moto droid phones the players that contacted me were using, the resolution didn’t adapt to the menu bar.

https://developer.android.com/training/system-ui/immersive.html

I believe that Immersive behavior is only available in 4.4 and above, but perhaps the other flags would still be useful to you?

I was recently looking into something similar myself, so this may or may not be helpful. Here is what I am using to go completely fullscreen.

private void HideSystemUI()
{
	if (Android.OS.Build.VERSION.SdkInt >= (Android.OS.BuildVersionCodes) 19)
	{
		View decorView = Window.DecorView;
		var uiOptions = (int)decorView.SystemUiVisibility;
		var newUiOptions = (int)uiOptions;

		newUiOptions |= (int)SystemUiFlags.LowProfile;
		newUiOptions |= (int)SystemUiFlags.Fullscreen;
		newUiOptions |= (int)SystemUiFlags.HideNavigation;
		newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;

		decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

		IsImmersive = true;
	}
}

Note that after hiding the navigation bar, you will have to query the real size of the screen from the activity. Like so:

Activity.WindowManager.DefaultDisplay.GetRealSize(Android.Graphics.Point size)

Hi @friendlytoaster, I’m trying to hide the system bar using your code block, but an error popped up:
Error CS0120: An object reference is required for the non-static field, method, or property ‘Android.Views.Window.DecorView.get’ (CS0120)
Which object reference should I use?

Also Android.Views.SystemUiFlags does not contain a definition for ImmersiveSticky – my game project targets Android 4.2 and above though. I wonder if there is a way to use ImmersiveSticky in my game for Android 4.4 and above?

@greyp I don’t have my project file in front of me, but you should be able to compile against 4.4, and still target 4.2 devices.

Hi,

Well, this solution hides the navigation bar, but if you touch the screen again, it is back, and that touch event is actually not being given to your app/game at all. So now you have to touch everything twice:

  • you hide the nav bar
  • first tap gives back the nav bar
  • second tap with the nav bar already on will actually do what it needs to do

Anyboday has any working solution? Starting to implement an Android Monogame, basically this is the first thing you need, full screen without any nav/status/action bars …

Thanks in advance!