Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 556
jbtamares Avatar asked Mar 06 '18 03:03

jbtamares


1 Answers

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.

like image 148
jbtamares Avatar answered Oct 22 '22 23:10

jbtamares