Search code examples
xamarinxamarin.formsxamarin.android

Xamarin Android WindowSoftInput Resize (specific page)


Is there a way to implement the Android.Views.SoftInput.AdjustResize to a specific page/control (e.g. a grid) rather than inserting it into App.xaml.cs or MainActivity.cs ?Since it is affecting my other pages when the keyboard is being shown.

Thanks!


Solution

  • I have solved my problem. What I did was to implement in on my page.xaml.cs on

    protected override void OnAppearing()
    {
        base.OnAppearing();
        App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
    } 
    

    This would resize your window when the keyboard is being shown when the page appears, and if you want to retain the normal behaviour of your Entry or other elements that will show your keyboard use this code:

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Pan);
    }
    

    The WindowSoftInputModeAdjust.Pan is the default behaviour of Android when a keyboard is being shown. This way when your page disappears, the settings will go back to default.