Moosen Moosen - 1 month ago 7
Android Question

Android WebView can't show the right border of the html table on some phones

I have a WebView in my XML file as below:

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


But it have a problem on some phones when it loads the website which has a
table, it can't show the right border of the table as the pic below on some phones like MI.But it fit well on Nexus and Samsung phones.
Also it doesn't work if I hide the scrollbar in xml or user the code as below.

mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);


Screenshot:

enter image description here

Answer Source

One way

And make true you add @JavascriptInterface

mWebView.getSettings().setDomStorageEnabled(true);

Another way

change to this.

<WebView android:id="@+id/webView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="none"/>

Edited

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.requestFocus();
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.loadUrl(url);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // add loadUrl
            view.loadUrl(url);
            return true;
        }
    }

Add@JavascriptInterface

@JavascriptInterface
public static void loadUrl(WebView webView, String url) {
   // do something here
}

You can check it.