androidandroid-webviewandroid-8.0-oreoandroid-chrome

Android Oreo WebView renders layout too small after 2nd loading


On some Android Oreo devices, when I load an url on webview for the first time, the URL page loads properly. However, when I load the URL again, the page is zoomed out. On devices lower than android oreo, the page loads properly for all devices.

Also, when you kill the app on the background and load again, the URL loads properly. On the second and succeeding tries, it shows the zoomed out version again. I attached the images of loaded URL below

Below is the correct loading of webpage on the webview Correct url webview photo

Below is the small display of webpage on webview webview Incorrect zoomed out url webview photo

Android XML Code:

<WebView
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Java Code:

    private WebView mWebView;
    mWebView = (WebView) view.findViewById(R.id.content_view);
    mWebView.loadUrl("https://policies.google.com/");

URL: https://policies.google.com/

Take note that this happen in other URLs too. https://policies.google.com/ is just an example

It works on the following: Huawei nova 2i RNE-L22, Android 8.0.0

It DOES NOT work on the following Android 8.1.0; Pixel 2 Android 8.0.0; Samsung SM-G950FD Android 8.0.1; Huawei P20 EML-L29

Any suggestions or reasons as why this happens? How to fix this?

Thanks in advance.


Solution

  • After asking google team about this issue, the said that it's probably some viewport layout settings. Webview has some unfortunate defaults due to legacy issues.,

    Adding webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); fixed the issue.