Android WebView is suitable for screen display

I try to set the contents of web pages on the screen, but it looks very ugly and shows different results, see the link for capturing the screen below:

http://postimg.org/image/jy0g268p1/0294ca52/

http://postimg.org/image/603z8qhab/e06b655e/

Below is the code:

WebSettings settings = webView.getSettings(); settings.setMinimumFontSize(30); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); settings.setBuiltInZoomControls(true); settings.setSupportZoom(true); webView.loadData(htmlContent, "text/html", "UTF-8"); webView.setInitialScale(1); webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

Please advise what should I do to fit the content? I really appreciate any help.

+5
source share
2 answers

I think I have found my own solution, which I put here for someone who needs it in the future. I just create one method to change the html chapter:

 public static String changedHeaderHtml(String htmlText) { String head = "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>"; String closedTag = "</body></html>"; String changeFontHtml = head + htmlText + closedTag; return changeFontHtml; } 

And I use it inside webview as follows:

 public static void displayHtmlText(String htmlContent, String message, WebView webView, RelativeLayout videoLayout, LinearLayout standardLayout, LinearLayout webviewLayout){ WebSettings settings = webView.getSettings(); settings.setMinimumFontSize(18); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); webView.setWebChromeClient(new WebChromeClient()); String changeFontHtml = Util.changedHeaderHtml(htmlContent); webView.loadDataWithBaseURL(null, changeFontHtml, "text/html", "UTF-8", null); webviewLayout.setVisibility(View.VISIBLE); standardLayout.setVisibility(View.GONE); videoLayout.setVisibility(View.GONE); } 

So, my content in a web browser is now suitable for the device and can display well.

+12
source

This worked for me:

 webview.Settings.LoadWithOverviewMode = true; webview.Settings.UseWideViewPort = true; 
+9
source

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


All Articles