Android应用程序中WebView中的html文本字段被软键盘隐藏 [英] html textfield in WebView in an Android application is hidden by the soft keyboard

查看:28
本文介绍了Android应用程序中WebView中的html文本字段被软键盘隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an Android application that is a TabHost with a WebView. I use it to load a specific html file that has a text field in its bottom part.

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

When I touch the html textfield, the soft keyboard pops up, and hides the textfield, so that I cannot see what I have typed.

这是布局:

<?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>

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

I have tried to configure the AndroidManifest.xml file with android:windowSoftInputMode="adjustResize" with no success. I have also tried replacing the FrameLayout in my layout with ScollView, but that caused my webview to increase in size indefinitely when the application is running.. this may be due to some javascript I have running on the page.

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

I have noticed that the android's web browser has a nifty behavior - in a web page, after the soft keyboard pops up, the web page scrolls smoothly so that the focusable textfield is visible to the user. How can I have this kind of behavior in my application?

推荐答案

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

I found a solution for this issue. (about a week after I posted the question; I only got to answering in stackoverflow today...)

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

I had pieces in my code that changed the WebView's height (to have room for a TabBar). Turns out that when you invoke setLayoutParams on a WebView, it will no longer change its height even if you have android:windowSoftInputMode="adjustResize" set.

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

I circumvented the need to change the WebView's height by adding the TabBar to the main.xml layout file, with an initial size of 0. When I increase the TabBar's size, the WebView's size decreases automatically, and it preserves the android:windowSoftInputMode="adjustResize" behavior.

这篇关于Android应用程序中WebView中的html文本字段被软键盘隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆