Android webview ignoring javascript command

knudsjeffknudsjeff Member ✭✭
edited January 15 in Xamarin.Android

Hello,
I currently have a webview in an Android app that has input fields. If the input is slightly off the top of the view but at a point that the user can still click on it, the webview pulls it to right above the keyboard. I want it at the top of the screen, so I tried adding a script tag with a scrollIntoView command to the HTML. The viewer runs this command if the android keyboard is hidden, but if it is up, the webview scrolls the input to right above the keyboard. Any suggestions on how to fix this?
Thanks!

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    Try to set WindowSoftInputMode to SoftInput.AdjustResize. The defaule value of the mode is AdjustPan, which doesn't resize the window when an input control has focus. Instead, the contents of the window are panned so that the current focus isn't obscured by the soft keyboard.

    The AdjustResize adjustment option could resize the window when an input control has focus, to make room for the soft keyboard.

    Check the tutorial:
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/soft-keyboard-input-mode

  • knudsjeffknudsjeff Member ✭✭

    Hello @Jarvan, thank you for the response. Unfortunately, however, the app doesn't handle resize very well. Do you have any other ideas?

  • JarvanJarvan Member, Xamarin Team Xamurai

    however, the app doesn't handle resize very well.

    How did you set the WindowSoftInputMode? You can set the property above the Activity class like below.

    [Activity(Label = "@string/app_name", 
        ...
        WindowSoftInputMode = Android.Views.SoftInput.AdjustResize)]
    public class MainActivity : AppCompatActivity
    
  • knudsjeffknudsjeff Member ✭✭

    @Jarvan, I ended up figuring out a way to mitigate it enough from the javascript. The softInputMode wouldn't work as this app doesn't resize well. Thanks for your help though!

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited 2:05PM

    If you've solved the issue, please mark your solution as the answer. It'll help others who face the similar problem.

  • knudsjeffknudsjeff Member ✭✭

    The way I fixed it didn't answer the question though. It was just a way to mitigate it on one or two devices.

Sign In or Register to comment.