How to set WindowSoftInputModeAdjust to Resize for a specific page?

308 Views Asked by At

In my MAUI project, I want to set the WindowSoftInputModeAdjust to Resize on a specific page and WindowSoftInputModeAdjust to Pan on other pages since it affects my other pages UI like below.

enter image description here

I tried using the code below, but it didn't work.

I added the below code on the cs page where I need the resize option:

protected override void OnAppearing()
{
try
{
    base.OnAppearing();
    App.Current.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
catch (Exception e)
{
    Debug.WriteLine("Exception:>>" + e);
}
}

protected override void OnDisappearing()
{
try
{
    base.OnDisappearing();
    App.Current.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Pan);
}
catch (Exception e)
{
    Debug.WriteLine("Exception:>>" + e);
}
}

I added the below code on the cs page where I need the pan option:

protected override void OnAppearing()
{
try
{
    base.OnAppearing();
    App.Current.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Pan);
}
catch (Exception e)
{
    Debug.WriteLine("Exception:>>" + e);
}
}

I set the WindowSoftInputModeAdjust to Pan on MainActivity.cs. Please provide a solution for this?

Update

The UI issue is happening on the home page only after the comment page keyboard open after the editor tap. If I view the comment page and without opening keyboard, no UI issue in home page. When keyboard is opening that page is resizing and as a result home page is also resizing.

Here is the full explanation video.

If I am not using resize option on the inner page, the header part is not visible on the UI like below screenshot:

enter image description here

That issue video.

1

There are 1 best solutions below

1
Liyun Zhang - MSFT On

First of all, there is an known issue: [regression/8.0.0] [Android] WindowSoftInputModeAdjust not working anymore. You can follow up it.

And then, you can use the android native platform code to set the WindowSoftInputModeAdjust.

protected override void OnAppearing()
{
try
{
    base.OnAppearing();
#if ANDROID 
    Platform.CurrentActivity?.Window?.SetSoftInputMode(Android.Views.SoftInput.AdjustResize);
#endif
}
catch (Exception e)
{
    Debug.WriteLine("Exception:>>" + e);
}
}

protected override void OnDisappearing()
{
try
{
    base.OnDisappearing();
#if ANDROID 
    Platform.CurrentActivity?.Window?.SetSoftInputMode(Android.Views.SoftInput.AdjustPan);
#endif
}
catch (Exception e)
{
    Debug.WriteLine("Exception:>>" + e);
}
}

In addition, you can use the Platform.CurrentActivity?.Window?.Attributes?.SoftInputMode to get the current SoftInputMode.