0

I have a Xamarin.Forms activity. I have wrapped scrollview around my content via:

<ScrollView
    HorizontalOptions="Center"
    VerticalOptions="Center">

When the natural height of the activity is higher then the display size, this allows scrolling. On the other hand, when the user clicks in a textbox and the soft keybaord pops up the user can't scroll to see what's behind the softkeyboard which is a problem.

Following a question for native android I added in my style file:

  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>

    <item name="windowActionBar">false</item>

    <item name="android:windowSoftInputMode">stateVisible|adjustResize</item>
    ...

Unfortunately, this doesn't give me my desired scrolling behavior when the soft-keyboard is up.

Christian
  • 25,249
  • 40
  • 134
  • 225

2 Answers2

2

You need to set WindowSoftInputMode in your MainActivity.cs.

This is how you can do it

[Activity(Label = "MyActivity", Theme = "@style/CustomTheme", WindowSoftInputMode = SoftInput.AdjustResize)]

Or put below line in OnCreate() method of MainActivity.

Window.SetSoftInputMode(Android.Views.SoftInput.AdjustResize);
Jaymin
  • 2,879
  • 3
  • 19
  • 35
  • It seems obvious to me how to do this if I have a straight Xamarin.Android activity. Unfortunately, it isn't clear to me how to do it with the Forms activity. Where do I put this? – Christian Mar 05 '19 at 11:11
  • Just put this line in the **MainActivity**. – Jaymin Mar 05 '19 at 11:11
  • I put it into my MainActivity right before that calls `LoadApplication(new App());`. Unfortunately, it doesn't have any effect. – Christian Mar 05 '19 at 12:05
  • `VerticalOptions="FillAndExpand"` to your scroll view and try. I have the same scenario. I have not set anything and it works fine with soft input. It manages by OS i guess. – Jaymin Mar 05 '19 at 12:23
1

There are multiple ways to do that, but this one is most in Xamarin spirit:

Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57