How to hide android buttons and draw on cut area (Android)

I try build my game on Android and want to use full screen. When I used unity there was an option no extend screen over cutout areas. How to do the same in monogame?

Hiding Android System Buttons
To hide android navigation buttons (back, home, etc):

Add this class to your AndroidActivity class:

class MyUiVisibilityChangeListener : Java.Lang.Object, View.IOnSystemUiVisibilityChangeListener
{
	View view;


	public MyUiVisibilityChangeListener(View view)
	{
		this.view = view;
		HideSystemUI();
	}


	public void OnSystemUiVisibilityChange(StatusBarVisibility visibility)
	{
		HideSystemUI();
	}


	private void HideSystemUI()
	{
		SystemUiFlags flags = SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky;
		view.SystemUiVisibility = (StatusBarVisibility)flags;
	}
}

Add _view.SetOnSystemUiVisibilityChangeListener(new MyUiVisibilityChangeListener(_view)); to OnCreate just before SetContentView(_view);

Also ensure your AndroidActivity class decorator looks something like this (you can google each of these options to better understand what they do):

[Activity(
	Label = "@string/app_name",
	MainLauncher = true,
	Icon = "@drawable/icon",
	AlwaysRetainTaskState = true,
	LaunchMode = LaunchMode.SingleInstance,
	ScreenOrientation = ScreenOrientation.SensorLandscape,
	ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize,
	Immersive = true,
	HardwareAccelerated = true
)]

Notch Issue
I’ve not run into the notch issue on android devices myself, but this is how I handled it for iOS. A better method would be to draw background at actual fullscreen and only important UI elements within the “safe area” or some such, but this was a simple way to just scale the whole screen to the safe area.

#if IOS
	// this is a load of non-sense to deal with iPhones having a notch and what not
	UIKit.UIWindow uiWindow = (UIKit.UIWindow)Program.game.Services.GetService(typeof(UIKit.UIWindow));
	if (uiWindow != null)
	{
		float iosDensity = (float)Microsoft.Maui.Devices.DeviceDisplay.MainDisplayInfo.Density;

		int top = (int)Math.Round(uiWindow.SafeAreaInsets.Top * iosDensity);
		int right = (int)Math.Round(uiWindow.SafeAreaInsets.Right * iosDensity);
		int bottom = (int)Math.Round(uiWindow.SafeAreaInsets.Bottom * iosDensity);
		int left = (int)Math.Round(uiWindow.SafeAreaInsets.Left * iosDensity);

		screenPos = new Point(left, top);
		screenSize = new Size(graphics.GraphicsDevice.Viewport.Width - left - right, graphics.GraphicsDevice.Viewport.Height - top - bottom);
	}
	else
	{
		screenPos = new Point(0, 0);
		screenSize = new Size(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);
	}
#else
	screenSize = new Size(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);
#endif

Assuming the Android method would end up being similar to the iOS approach, you’ll need Maui Essentials to get the screen’s DPI to calc the safe zone. Which can be done by adding <UseMauiEssentials>true</UseMauiEssentials> to your .csproj. At this point Maui Essentials may even have methods/members to get the safe zone without needing the native API at all.