[英]fromHtml: Different behaviour on JellyBean and KitKat (and above)
I am using fromHtml
to display formatted text (bold italic etc) in TextView
. 我正在使用
fromHtml
在TextView
显示格式化的文本(粗体斜体等)。 However, I found it's behaviour is different on JellyBean (4.1.2) and KitKat(4.4.2) 但是,我发现它在JellyBean(4.1.2)和KitKat(4.4.2)上的行为不同
Here is code: 这是代码:
String myHtml = "<b>hello</b>😄";
Spanned spanned = Html.fromHtml(myHtml, null, null);
Here html string has 😄
此处的html字符串具有
😄
which is unicode for an emoji. 这是表情符号的unicode。 Now after calling
fromHtml
it returns following value on KitKat (and above): 现在,在从
fromHtml
调用fromHtml
它将在KitKat(及更高版本)上返回以下值:
spanned = hello😄
Here is screenshot of Android Studio for the same: 这是相同的Android Studio屏幕截图:
This is expected behaviour as we can see corresponding emoji in spanned
. 这是正常现象,因为我们可以看到相应的表情符号
spanned
。
But on JellyBean the same call returns following value: 但是在JellyBean上,相同的调用返回以下值:
spanned = hello��
Here is screenshot: 这是屏幕截图:
This is indeed not expected and driving me nuts. 这确实是意料之外的,这让我发疯。 I don't know what I am doing wrong.
我不知道我在做什么错。 If anyone having idea please can you help?
如果有人有想法,请您能帮忙吗?
Surprisingly, root of this problem was in Html.toHtml
which I had used to convert text in TextView
to html. 出乎意料的是,此问题的根源是我用来将
TextView
文本转换为html的Html.toHtml
。 I used custom toHtml
and this problem solved. 我使用自定义
toHtml
并解决了这个问题。 I used .toHtml
written in this answer. 我用这个答案中写的
.toHtml
。 Indeed it is great solution. 确实,这是一个很好的解决方案。 I wonder how Android's original
Html.toHtml
is so lame and defective. 我不知道Android的原始
Html.toHtml
如何如此Html.toHtml
和有缺陷。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.