Issue
I've developed a web application for Firefox OS, but I wanted to make it run "natively" in Android. My application consists of a dialogue box that is a div
which fills the entire page when visible, which I've tested using the Firefox responsive design tool and it does resize correctly. When a soft keyboard appears, I would want the dialogue to resize to the viewport left over as there are some buttons at the bottom of the dialogue.
I created an application with a single activity that contains just a WebView
. I wanted to the view to resize when the keyboard appears, so I used:
android:windowSoftInputMode="stateUnspecified|adjustResize"
which didn't seem to make any difference to the WebView
when the keyboard was visible. I looked online and there were many people complaining about this problem, but they all had the same thing in common, they were using the Theme.Black.NoTitleBar.Fullscreen
theme, which I am not. I tried all of the solutions to that problem, but none of them worked.
I then began to wonder if there was a bug in WebView
which meant it didn't resize. So, I wrote a custom View
which 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 sure enough, the view was being resized correctly when the keyboard appeared and disappared. So, I did some more research and I found a few answers that said that you need to hide the WebView
, reload it, and then 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 point, this is a web-app with a single .html file and JS causes the state of all the elements in the app to change in runtime, so reloading it is not an option.)
My question is whether anyone knows of a way of resizing a WebView
once the content has been loaded when the keyboard is visible.
Solution
The problem turned out to be that I was using position: absolute
inside a position: fixed
div
. The outer div
was resizing properly, but the inner one was not. The reason I had to use position: absolute
was because there is a bug in WebKit which means that you cannot transform
fixed
positioned divs.
Answered By - Tom Leese
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.