Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html textfield in WebView in an Android application is hidden by the soft keyboard

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?

like image 216
gardenofwine Avatar asked Apr 28 '10 13:04

gardenofwine


2 Answers

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>
like image 147
Sandro Avatar answered Nov 11 '22 12:11

Sandro


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.

like image 33
gardenofwine Avatar answered Nov 11 '22 12:11

gardenofwine