locked
Android webview ignoring javascript command RRS feed

  • Question

  • User392254 posted

    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!

    Wednesday, January 15, 2020 10:20 PM

All replies

  • User382871 posted

    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

    Thursday, January 16, 2020 9:37 AM
  • User392254 posted

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

    Thursday, January 16, 2020 2:03 PM
  • User382871 posted

    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

    Friday, January 17, 2020 8:15 AM
  • User392254 posted

    @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!

    Friday, January 17, 2020 2:03 PM
  • User382871 posted

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

    Friday, January 17, 2020 2:05 PM
  • User392254 posted

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

    Friday, January 17, 2020 2:06 PM
  • User383181 posted

    @knudsjeff did you find a solution?

    Wednesday, September 9, 2020 10:50 PM
  • User392254 posted

    @Pooja105 not really. Just was able to modify some javascript on the page so it worked slightly better.

    Friday, September 11, 2020 6:43 PM