如何在TextView中设置Unicode以在Android中显示表情符号? [英] How to set unicode in textview to show emoji in android?

查看:733
本文介绍了如何在TextView中设置Unicode以在Android中显示表情符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器以json字符串格式获取了一些Unicode字符串(表情符号图标)。

I am getting some Unicode string(emoji icons) from server in json string format.

我的问题很奇怪,我正在尝试最后两天来解决此问题问题。当我解析json并将所有Unicode字符串存储在 ArrayList< String> 中并尝试通过从同一ArrayList获取值来设置TextView上的文本时,它将Unicode字符显示为:

My problem is strange and I am trying for last two days to resolve this issue. When I parse json and store all the Unicode string in an ArrayList<String> and try to set the text on TextView by getting value from the same ArrayList then it shows Unicode characters as :

Ghcghchgc \ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3

Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3

,当我通过传递静态值在textview上设置相同的字符串时:
textview.settext( Ghcghchgc\ud83d \ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3)

and when the same string I set on textview by passing static value as : textview.settext("Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3")

然后,textview显示完美的表情符号。

then the textview is showing perfect emojis.

我被困在这一点上。有人可以帮我解决这个问题,或者告诉我我做错了什么吗。

I am stuck at this point. Can anybody please help me to resolve this issue or tell me if I am doing something wrong.

推荐答案

这听起来像是您想要从JSON中获取字符串。如果您不介意添加库,请 Apache Commons具有一个String.unescapeJava 函数,它可以满足您的需要。如果您不想添加该库,请参见此答案

This sounds like you want to unescape your string that you've got from JSON. If you don't mind adding a library, Apache Commons has a String.unescapeJava function which does what you need. If you don't want to add that library, see this answer.

这篇关于如何在TextView中设置Unicode以在Android中显示表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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