Problem with Android web browser with SINGLE_COLUMN mode

I am currently having a problem with Android WebView . This web view is currently initialized as follows:

 _post_WebView = (WebView) view.findViewById(R.id.post_webview); _post_WebView.setBackgroundColor(Color.WHITE); _post_WebView.setWebViewClient(new PostWebViewClient()); _post_WebView.getSettings().setBuiltInZoomControls(true); _post_WebView.getSettings().setSupportZoom(true); _post_WebView.getSettings().setPluginState(PluginState.ON); _post_WebView.getSettings().setJavaScriptEnabled(true); _post_WebView.getSettings().setRenderPriority(RenderPriority.HIGH); _post_WebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); _post_WebView.setWebChromeClient(new WebChromeClient() {}); _post_WebView.getSettings().setUseWideViewPort(false); _post_WebView.getSettings().setLoadWithOverviewMode(true); _post_WebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 

This web view is used to display the HTML string received from the server. (Using the loadData method). Now the problem is that in SINGLE_COLUMN mode SINGLE_COLUMN images and text change correctly both in width and in height, but the embedded YouTube videos, but with a change in size in width, do not change in height and, therefore, show nothing but black box.

In LayoutAlgorithm.NORMAL everything works fine. How can I make sure the youtube videos change correctly in the SINGLE_COLUMN algorithm?

Youtube videos are embedded as follows:

 <iframe allowfullscreen="" frameborder="0" height="315" width="420" src="YOUTUBE_VIDEO_LINK"></iframe> 
+3
source share
1 answer

I finally went and solved it using loadDataWithBaseURL(null, htmlString, "text/html", "utf-8", null) instead of loadData(htmlString,"text/html","utf-8") , adding in iframes using CSS property 100% max-width and property auto width and height .

 htmlString = "<html><head><style>iframe {max-width: 100%; width:auto; height: auto;}</style></head><body>"+htmlString+"</body></html>"; 

This is not the cleanest way to do this, but it works.

This method should also work if used with the NARROW_COLUMNS algorithm.

+4
source

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


All Articles