HTML.fromHtml换行符消失 [英] HTML.fromHtml Line Breaks Disappearing

查看:2290
本文介绍了HTML.fromHtml换行符消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在跨区文字从一个EditText框,将其转换为HTML使用HTML.toHtml标记的字符串。这工作得很好。我已经验证字符串是正确的,并包含一个
在适当的位置。然而,当我到了标记的字符串转换回跨区文本来填充一个TextView或使用的EditText HTML.fromHtml的
(或多个的,如果他们是present)在第一个段落的结束而消失。这意味着,如果用户输入的文本有多个换行,并希望保持这种格式化丢失。

I am taking Spanned Text from an EditText box and converting it to a HTML tagged string using HTML.toHtml. This works fine. I have verified that the string is correct and contains a
in the appropriate location. However, when I got to convert the tagged string back to a spanned text to populate a TextView or EditText using HTML.fromHtml the
(or multiple ones if they are present) at the end of the first paragraph disappear. This means that if a users entered text with multiple line breaks and wanted to keep that formatting it gets lost.

我附上图片,以帮助说明这一点。第一次的EditText是用户输入,TextView的下面这是它的EditText上述情况,下面的EditText它使用HTML.fromHtml使用字符串在它上面的TextView被填充的HTML.tohtml结果。正如你所看到的休息时间都消失了线等有多余的线条。此外,当第二编辑文本的跨区文本通过HTML.toHtml运行它现在产生一个不同的HTML标记的字符串。

I attached a picture to help illustrate this. The first EditText is the user input, the TextView Below it is the HTML.tohtml result of the EditText above it, the EditText below it is populated using HTML.fromHtml using the string in the TextView above it. As you can see the line breaks have disappeared and so have the extra lines. Furthermore, when the spanned text of the second edit text is run through the HTML.toHtml it now produces a different HTML tagged String.

我希望能够采取的HTML标记的字符串从第一的EditText和填充等TextViews或EditTexts又不失换行符和格式。任何建议将是有益的。

感谢

推荐答案

我也有这个问题,我无法找到一个简单的改造什么都解决方案。注意一些重要的东西,当用户presses输入java的产生特殊字符,但在HTML中存在对换行没有这样的格式。这是< BR />

I also had this problem and I could not find an easy "transform" or something alike solution. Note something important, when the user presses "enter" java produces the special character \n but in HTML there is no such format for line breaking. It is the <br />.

所以,我所做的一切是为了取代一些具体的的CharSequence S,从纯文本,以替代HTML格式。在我的情况下,只有回车字符所以并不杂乱。

So what I have done was to replace some specific CharSequences, from the plain text, by the alternative HTML format. In my case there was only the "enter" character so it was not that messy.

这篇关于HTML.fromHtml换行符消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆