I developed a web application for Firefox OS, but I wanted it to run โnativelyโ in Android. My application consists of a dialog box, which is a div that fills the entire page when it is visible, which I tested using the Firefox responsive development tool, and it resizes correctly. When the soft keyboard appears, I want the dialog to change to the viewport on the left, as there are several buttons at the bottom of the dialog.
I created a single-action application that contains only a WebView . I wanted the view to change when the keyboard appeared, so I used:
android:windowSoftInputMode="stateUnspecified|adjustResize"
which seemed to make no difference to WebView when the keyboard was visible. I looked online and many people complained about this problem, but they all had the same thing in common, they used Theme.Black.NoTitleBar.Fullscreen theme, which I am not. I tried all the solutions to this problem, but none of them worked.
Then I began to wonder if there was an error in the WebView , which meant that it did not change. So, I wrote a custom View that printed the dimensions in onLayout .
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.d(TAG, t + " " + r + " " + b + " " + l); }
And, of course, the view was correctly changed when the keyboard appeared and disappeared. So, I did some more research, and I found a few answers that said you need to hide the WebView , reload it and show it again.
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.d(TAG, t + " " + r + " " + b + " " + l); mWebView.setVisibility(View.GONE); mWebView.layout(l, t, r, b); mWebView.invalidate(); mWebView.reload(); mWebView.setVisibility(View.VISIBLE); }
Again, this did not solve my problem. (And as a side item, this web application with a single .html and JS file changes the state of all elements in the application at run time, so reloading is not an option.)
My question is, does anyone know of a way to resize WebView after loading content when the keyboard is visible.