2010-04-28 22 views
7

我有一個Android應用程序,它是一個帶有WebView的TabHost。我用它來加載一個特定的html文件,它的底部有一個文本字段。在Android應用程序的WebView中的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的網絡瀏覽器有一個漂亮的行爲 - 在網頁中,彈出軟鍵盤後,網頁平滑滾動,以便用戶可見焦點文本框。我如何在我的應用程序中有這種行爲?

+0

解決此問題的方法可能會在軟鍵區出現時得到通知,然後手動調整webview的大小。 我已嘗試在所有佈局類中實現onCreateInputConnection(EditorInfo),但鍵盤出現時無法獲得通知。 幫助! – gardenofwine 2010-04-29 07:44:48

回答

4

我找到了解決此問題的解決方案。 (我發佈了這個問題後大約一週;我只能在今天的計算器中回答...)

我在代碼中改變了WebView的高度(爲TabBar留出空間)。原來,當你在WebView上調用setLayoutParams時,即使你設置了android:windowSoftInputMode="adjustResize",它也不會再改變它的高度。

我繞過了通過將TabBar添加到main.xml佈局文件,初始大小爲0來改變WebView的高度的需求。當我增加TabBar的大小時,WebView的大小自動減小,並且它保留android:windowSoftInputMode="adjustResize"行爲。

+0

不知道這是否是WebView的已知錯誤?剛剛偶然發現了同樣的問題 – 2012-09-27 15:39:11

+0

當天我沒有提出這個問題的錯誤。當時我正在使用的Android API版本是1.6或2.2(我不記得) – gardenofwine 2012-10-02 13:04:32

+0

我有一個更復雜的佈局,所以修復更困難,但最後我做了同樣的事情,並且繞過了調用webView的固定高度的setLayoutParams – 2012-10-02 17:25:59

7

我越來越瘋狂沒有任何作品android:windowSoftInputMode="adjustResize"可能會幫助,但一定要讓你的應用程序不全屏。

刪除我的應用程序的全屏解決了與softkeyboard的佈局調整大小的問題。

<item name="android:windowFullscreen">false</item> 
+1

請注意,如果'windowFullscreen'設置爲'true','adjustResize'將不起作用。 – 2014-02-26 12:09:03

+1

我很肯定這就是他所說的。 – 2015-02-26 11:33:35