html textfield in WebView in an Android application is hidden by the soft keyboard
Solution 1
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.
Solution 2
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>
Related videos on Youtube
gardenofwine
Updated on April 20, 2022Comments
-
gardenofwine about 2 years
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 theFrameLayout
in my layout withScollView
, but that caused mywebview
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?
-
Display name over 11 yearsDo know whether this is a known bug of the WebView? Just stumbled across the same problem
-
gardenofwine over 11 yearsI 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)
-
Display name over 11 yearsI 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
-
Anas Azeem over 10 yearsCan 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. -
Mithun Sreedharan about 10 yearsNote that
adjustResize
will not work ifwindowFullscreen
is set totrue
-
Aleksei Kosozhikhin about 9 yearsI'm pretty sure that's what he said.