【发布时间】:2011-02-13 08:51:01
【问题描述】:
我有一个 Android 应用程序,它是一个带有 WebView 的 TabHost。我用它来加载一个特定的 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>
我尝试使用android:windowSoftInputMode="adjustResize" 配置AndroidManifest.xml 文件,但没有成功。我还尝试用ScollView 替换布局中的FrameLayout,但这导致我的webview 在应用程序运行时无限增大。这可能是由于我在页面上运行了一些javascript。
我注意到android的网络浏览器有一个漂亮的行为——在网页中,软键盘弹出后,网页平滑滚动,用户可以看到可聚焦的文本字段。我的应用程序中怎么会有这种行为?
【问题讨论】:
-
解决此问题的方法可能是在出现软键盘时收到通知,然后手动调整 web 视图的大小。我已经尝试在我的所有布局类中实现 onCreateInputConnection(EditorInfo),但是当键盘出现时无法收到通知。救命!
标签: android keyboard webview textfield