简体   繁体   English

Xamarin Forms 3.6 Webview Android:软键盘隐藏了Webview中的输入字段

[英]Xamarin Forms 3.6 Webview Android: Softkeyboard hides entry fields in Webview

We have a Xamarin Forms View with just a Toolbar and a WebView. 我们有一个Xamarin Forms视图,只有一个工具栏和一个WebView。

ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         Title="TestApp"
         x:Class="TestApp.Client.Views.MainPage">
<ContentPage.ToolbarItems>
    <ToolbarItem
        Order="Primary" 
        Icon="ic_settings.png"
        Clicked="OnSettingsClicked"
        AutomationId="mnuSettings"
        Priority="1"
        x:Name="mnuSettings"
        Text="Settings"
    />
</ContentPage.ToolbarItems>
<WebView"
    Source="{Binding URL}">
</WebView>

When the WebView contains a HTML text field and the field gets the focus, the soft keyboard opens but hides the text field. 当WebView包含HTML文本字段并且该字段获得焦点时,软键盘将打开但隐藏文本字段。 We are currently using Xamarin.Forms 3.6. 我们目前正在使用Xamarin.Forms 3.6。 We have tried already many things, which we found on th web, but nothing worked, yet. 我们已经尝试了很多东西,我们在网上找到了,但没有任何效果。

When we put the WebView inside a ScrollView, together with an Xamarin Form Entry Field, the entry field moves up, when the soft keyboard displays, which means that the AdjustResize behavior seems to work basically, but not with the WebView. 当我们将WebView放在ScrollView中时,与Xamarin表单输入字段一起,当软键盘显示时,输入字段向上移动,这意味着AdjustResize行为似乎基本上起作用,但不适用于WebView。

Setting the WindowSoftInputMode to AdjustResize does not change anything. 将WindowSoftInputMode设置为AdjustResize不会更改任何内容。

Does anyone have an idea? 有没有人有想法?

You can solve this problem by the following steps: 您可以通过以下步骤解决此问题:

1 Detect whether soft keyboard is showing using code like: 1使用以下代码检测是否显示软键盘:

    var inputMethodManager = (InputMethodManager)this.GetSystemService(Context.InputMethodService);
    var keyboardIsShown = inputMethodManager.IsAcceptingText;

2 Commit an animation to scroll up the page when keyboard is showing. 2提交动画以在显示键盘时向上滚动页面。

3 Commit an animation to scroll down the page when keyboard is hidden. 3隐藏键盘时,提交动画以向下滚动页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM