gpt4 book ai didi

android - 需要在 HTML webview 中显示文本格式的数据,如 Stack Overflow

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:27 24 4
gpt4 key购买 nike

我有纯文本数据,根据间距行等格式化。但我想将此文本显示为 HTML?如何才能做到这一点。

[American Thinker]

March 1, 2016
[American Thinker] [Navigation Menu]
HomeArchivesVideoCartoonsAboutSearchLoginRules/FAQContactDonations
Merchandise <http://www.americanmethod.com/american-thinker/>
Home Archives Video Cartoons About Search Login More [Down Arrow]
* Rules/FAQ
* Contact
* Donations
* Merchandise <http://www.americanmethod.com/american-thinker/>


American Thinker Blog

Mexican oil giant devastated by oil price decline - 3/1/16 March 1, 2016
The state owned oil company that provides one third of the revenue of the
Mexican government is in a deep crisis, owing to low oil prices,

我想像在网络上的 stackoverflow 上显示的那样显示。

问题是,当我把它放在一个段落中时,它看起来都串在一起了。

支持相反的操作 Html.fromHtml(htmlString),但如何将文本转换为 HTML 中正确显示的内容?在我发布之前没有想到它,但真的希望它看起来就像这个编辑文本。

更新:

    <PRE> </PRE>  

做了一些我想要的但现在没有发生换行所以必须向右或向左滚动。

更新:按照下面的建议添加,我现在可以换行,但有些行如下所示:

    The state owned oil company that
provides one third of the revenue of
the
Mexican government is in a deep crisis,
owing to low oil prices,
inefficiency, and corruption. The
implications for the United States are
important. More
The Calamitous Climate at
etc etc

这是我的 html:

       String htmlstuff = " \n" +
"<html>\n" +
"<header><title>This is title</title></header>\n" +
"<body>\n" +


"<pre style=\"white-space: pre-wrap;\">\n";

htmlstuff=htmlstuff+result;
htmlstuff=htmlstuff+
" </pre>\n"+

"</body>\n" +
"</html>\n";
wv.loadDataWithBaseURL("", htmlstuff, "text/html", "UTF-8", "");

wv.setHorizontalScrollBarEnabled(false);

最佳答案

考虑这个 Html display formatted text

你只需要将你的文字放在

<pre>

标记并使用 CSS

white-space: pre-wrap;

属性显示它没有像这样的水平滚动

<pre style="white-space: pre-wrap;">
Formated text
Line 2 with wide spaces
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</pre>

关于android - 需要在 HTML webview 中显示文本格式的数据,如 Stack Overflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35723872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com