問題描述
我有一個 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文本字段被軟鍵盤隱藏的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!