软件键盘隐藏了Android应用程序中WebView中的html文本字段

gar*_*ine 7 keyboard android textfield webview

我有一个带有WebView的TabHost的Android应用程序.我用它来加载一个特定的html文件,其底部有一个文本字段.

当我触摸html文本字段时,软键盘会弹出,并隐藏文本字段,这样我就看不到输入的内容了.

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <TabWidget
            android:focusableInTouchMode="false"
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="63dp" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/layout"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
                <WebView
                    android:id="@+id/webview"
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent"
                    android:layout_weight="1" />
            </LinearLayout>
        </FrameLayout>      
    </LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)

我试图配置AndroidManifest.xml文件但android:windowSoftInputMode="adjustResize"没有成功.我也尝试用FrameLayout我的布局替换ScollView,但这导致我webview在应用程序运行时无限期地增加大小..这可能是由于我在页面上运行的一些javascript.

我注意到android的网页浏览器有一个漂亮的行为 - 在网页中,弹出软键盘后,网页流畅地滚动,以便用户可以看到可聚焦的文本字段.我怎样才能在我的应用程序中出现这种行为?

San*_*dro 8

我疯android:windowSoftInputMode="adjustResize"了似乎任何工作可能没有帮助,但一定要让你的应用程序不全屏.

删除我的应用程序的全屏解决了布局调整大小与软键盘的问题.

<item name="android:windowFullscreen">false</item>
Run Code Online (Sandbox Code Playgroud)


gar*_*ine 5

我找到了这个问题的解决方案。(在我发布问题大约一周后;我今天只能在 stackoverflow 中回答......)

我的代码中有一些片段改变了 WebView 的高度(为 TabBar 留出空间)。事实证明,当您在 WebView 上调用 setLayoutParams 时,即使您已android:windowSoftInputMode="adjustResize"设置,它也不会再更改其高度。

我通过将 TabBar 添加到 main.xml 布局文件中来避免更改 WebView 高度的需要,初始大小为 0。当我增加 TabBar 的大小时,WebView 的大小会自动减小,并且保留了android:windowSoftInputMode="adjustResize"行为。