7

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.

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

Here is the layout:

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

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.

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?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
gardenofwine
  • 1,344
  • 2
  • 15
  • 24
  • A way to get around this issue may be get notified when the soft keybaord appears, and then resize manually the webview. I have tried implementing onCreateInputConnection(EditorInfo) in all my layout classes, but could not get a notification when the keyboard appears. Help! – gardenofwine Apr 29 '10 at 07:44

2 Answers2

8

I was getting crazy nothing works android:windowSoftInputMode="adjustResize" may help but be sure to have your app not in full screen.

Removing full screen for my app solved the problem with the layout resize with softkeyboard.

<item name="android:windowFullscreen">false</item>
duggu
  • 37,851
  • 12
  • 116
  • 113
Sandro
  • 701
  • 6
  • 12
5

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

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.

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.

duggu
  • 37,851
  • 12
  • 116
  • 113
gardenofwine
  • 1,344
  • 2
  • 15
  • 24
  • Do know whether this is a known bug of the WebView? Just stumbled across the same problem – Display name Sep 27 '12 at 15:39
  • I did not file a bug for this issue back in the day. Back then the Android API version I was working on was 1.6, or 2.2 (I can't remember) – gardenofwine Oct 02 '12 at 13:04
  • I had a more complex layout, so a fix was harder, but in the end I did the same as you did and circumvented to call setLayoutParams with a fixed height for the webView – Display name Oct 02 '12 at 17:25
  • Can you show the code how you did the `setLayoutParams()` with your webview. I am really stuck at this very problem and is unable to find a solution yet. Please update your answer. – Anas Azeem Nov 21 '13 at 06:59