Skip to content

Instantly share code, notes, and snippets.

@jimmgarrido
Last active December 12, 2019 05:36
Show Gist options
  • Save jimmgarrido/e36033b26f01e8da091fd321d41d991a to your computer and use it in GitHub Desktop.
Save jimmgarrido/e36033b26f01e8da091fd321d41d991a to your computer and use it in GitHub Desktop.
AdjustResize Workaround for Xamarin.Forms

Forms 2.3.3+

Uses the new Platform Specifics feature

protected override void OnCreate(Bundle bundle)
{
	ToolbarResource = Resource.Layout.toolbar;
	TabLayoutResource = Resource.Layout.tabs;

	base.OnCreate(bundle);

	//Remove the status bar underlay in API 21+
	if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
	{
		Window.DecorView.SystemUiVisibility = 0;
		var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
		statusBarHeightInfo.SetValue(this, 0);
		Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
	}


	global::Xamarin.Forms.Forms.Init(this, bundle);
	LoadApplication(new App());

	App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}

Forms 2.3.2 and below

protected override void OnCreate(Bundle bundle)
{
	ToolbarResource = Resource.Layout.toolbar;
	TabLayoutResource = Resource.Layout.tabs;

	base.OnCreate(bundle);
	Window.SetSoftInputMode(SoftInput.AdjustResize);

	//Remove the status bar underlay in API 21+
	if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
	{
		Window.DecorView.SystemUiVisibility = 0;
		var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
		statusBarHeightInfo.SetValue(this, 0);
		Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
	}

	global::Xamarin.Forms.Forms.Init(this, bundle);
	LoadApplication(new App());
}
@Adit2705
Copy link

When we use this white screen appears at the time of hiding the keyboard.Any workaround on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment