正确渲染UNI code字符的TextView? [英] Rendering a unicode character correctly in TextView?

查看:170
本文介绍了正确渲染UNI code字符的TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到从服务器(我的应用程序运行在Android上)发送到我的字符串。人物之一是单向code符号是一个音符。我从一个字符串服务器的响应,然后直接把它交给一个TextView。这是应该出现什么:

 

而是我看到的只是一个块(有点样子):

  []

当我打印到logcat的字符串,我看到:

 

我不知道怎么去TextView中正确显示字符。我想这样的:

  tv.setText(Html.fromHtml(文本)的ToString());

但它仍然呈现出块。什么是做到这一点的正确方法?

感谢

--------------------更新-------------------------- ---

我尝试只是创造在它的字符一个网页,然后指着(在我的Nexus One)系统浏览器页面。同样的渲染问题,貌似字形该字符并不存在:

 < HTML和GT;
  <身体GT;
    &安培;#x266B;
    < BR />
    &放大器;#9835;
  < /身体GT;
< / HTML>


解决方案

您可以尝试寻找到这个包:

org.apache.commons.lang。 StringEscapeUtils

它包含UNI code字符的能力unescapeHtml和unescapeXml。不过,Android使用Droid的字体,我不认为在该字体音符字符存在。你必须以某种方式包含的字体确实包含该字符与您的应用程序,然后使用StringEscapeUtils从哪些服务器发送到要显示的内容进行转换。

I'm getting a string sent to me from a server (my app is running on android). One of the characters is a unicode symbol which is a musical note. I take the response from the server in a String, then hand it directly to a TextView. This is what should appear:

but instead I see just a block (kinda looks like):

[]

when I print the string to logcat, I see:

â«

I'm not sure how to get TextView to display the character correctly. I tried this:

tv.setText(Html.fromHtml(text).toString());

but it's still rendering out the block. What's the right way to do this?

Thanks

-------------------- Update -----------------------------

I tried just creating a webpage with the character in it, then pointing the system browser to the page (on my nexus one). Same render issue, looks like the glyph for that character just does not exist?:

<html>
  <body>
    &#x266B;
    <br />
    &#9835;
  </body>
</html>

解决方案

You might try looking into this package:

org.apache.commons.lang.StringEscapeUtils

It has the ability to unescapeHtml and unescapeXml that contains unicode characters. However, Android is using the Droid font, and I don't think the musical note character exists in that font. You'll have to somehow include a font that does include that character with your app, then use StringEscapeUtils to convert from what the server sends to what you want to display.

这篇关于正确渲染UNI code字符的TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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