8

我目前正在从网站(论坛)获取 HTML,对其进行修改,并将其显示在 WebView 中。然而,有时,有些字符串很长并且没有任何 WebView 认为允许换行的字符,因此 WebView 会水平拉伸并引入水平滚动。我讨厌水平滚动,我想强制 WebView 将这些行换成新行,而不管 WebView 是否喜欢它在前面换行的字符。

注意:我确实希望 WebView 仍然可以垂直扩展和滚动。

4

2 回答 2

5

使用以下样式打破所有类型的单词。 参考链接 css-tricks.com

 style="overflow-wrap: break-word; word-wrap: break-word; -ms-word-break: break-all; word-break: break-all; word-break: break-word; -ms-hyphens: auto; -moz-hyphens: auto; -webkit-hyphens: auto; hyphens: auto; "

演示

String html ="<html> <head><meta name=\"viewport\" content=\"width=device-width, user-scalable=0,initial-scale=1.0\"></head><body style=\"overflow-wrap: break-word; " +
                "word-wrap: break-word; -ms-word-break: break-all; word-break: break-all; word-break: break-word; -ms-hyphens: auto; -moz-hyphens: auto; -webkit-hyphens: auto; hyphens: auto; \">" +
                YourHtmlText +"</body></html>";

webView.loadDataWithBaseURL(null, html, "text/html", "utf-8",
                "about:blank");
于 2019-11-12T21:36:54.900 回答
0

将此功能添加到您的网络视图

 myWebView.loadUrl("javascript:stopScrolling()");

在你的 index.html 中添加这个函数

function stopScrolling()
{
    document.ontouchmove = function(e){ e.preventDefault(); }
}
于 2012-11-26T05:08:24.630 回答