首页 > 解决方案 > Xamarin Forms 3.6 Webview Android:软键盘隐藏 Webview 中的输入字段

问题描述

我们有一个只有一个工具栏和一个 WebView 的 Xamarin 表单视图。

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>

当 WebView 包含 HTML 文本字段并且该字段获得焦点时,软键盘打开但隐藏文本字段。我们目前正在使用 Xamarin.Forms 3.6。我们已经尝试了很多东西,我们在网上找到了这些东西,但还没有奏效。

当我们将 WebView 与 Xamarin Form Entry Field 一起放入 ScrollView 时,输入字段向上移动,当软键盘显示时,这意味着 AdjustResize 行为似乎基本可以正常工作,但不能与 WebView 一起工作。

将 WindowSoftInputMode 设置为 AdjustResize 不会改变任何内容。

有人有想法吗?

标签: androidformsxamarinwebviewandroid-softkeyboard

解决方案


您可以通过以下步骤解决此问题:

1 使用如下代码检测软键盘是否显示:

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

2 提交动画以在显示键盘时向上滚动页面。

3 提交动画以在键盘隐藏时向下滚动页面。


推荐阅读