4
votes

I am trying to load some HTML data into Android Webview. The data is in the form of string that is loaded from a web service and the HTML can contain embedded youtube videos which I want to embed inline and make playable.

Everything works fine with LayoutAlgorithm.NORMAL. But when I use the SINGLE_COLUMN layout algorithm, the Youtube videos show up as black boxes that cannot be played anymore. I need a single column format as the images inside the HTML overflow the webview width in NORMAL mode. Here's my code to configure the webview.

// Set maximum image width to fit screen
contentWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

// Make non focusable to prevent links from being selectable.
contentWebView.setFocusableInTouchMode(false);
contentWebView.setFocusable(false);

// Enable HTML5 video
contentWebView.getSettings().setJavaScriptEnabled(true);
contentWebView.getSettings().setPluginState(PluginState.ON);
contentWebView.setWebChromeClient(new WebChromeClient() {
});

Is it possible to somehow make the videos playable with SINGLE_COLUMN layout or emulate the single column layout manually while applying the NORMAL layout algorithm? Any other ideas?

1

1 Answers

0
votes

LayoutAlgorithm.SINGLE_COLUMN - is deprecated on google developers. You have to change width/height of elements in your html string if you can.

In my case i replace all height="", width="" - and it works great without any setLayoutAlgorithm() settings. Or try this solution