WebView does not resize

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.

+6
source share
2 answers

The problem turned out to be that I used position: absolute inside position: fixed div . The outer div was correctly modified, but there was no inner div . The reason I had to use position: absolute was because there is a bug in WebKit that means you cannot transform fixed position divs.

+2
source

This is not quite the answer to your question, but you will also notice that WebView does have a size when it gets larger, but does not decrease when the height of the content decreases, as I already answered this question: WebView height = wrap_content with font resizing not works

The bug / feature is referenced by the Google tracker: https://code.google.com/p/android/issues/detail?id=18726

Please do not blame me, I just wanted to point out that for further problems you may run into WebView.

+4
source

Source: https://habr.com/ru/post/952015/


All Articles