简体   繁体   English

如何使用Html.fromHtml在android中显示心脏标志

[英]How to show heart sign in android using Html.fromHtml

In my app I am fetching some data from the server, the data might contain some unicode characters like heart, etc. 在我的应用程序中,我从服务器获取一些数据,数据可能包含一些像心脏等的unicode字符。

Now I can show a black heart symbol using unicode format, this way 现在,我可以使用unicode格式显示黑心符号

String str = "\u2764";//unicode character for black heart
TextView txtv = (TextView)findViewById(R.id.txtv);
txtv.setText(txtv.getText()+str);

but I'm setting the text like this: 但我正在设置这样的文字:

holder.txt_cardDesc.setText(Html.fromHtml(cardsDataClass.getCarddesc()));

cardsDataClass.getCarddesc() returns "âÂÂ¥All is changing soon, Christmas coming and we pray to God for all to..." cardsDataClass.getCarddesc()返回“â¥所有即将改变,圣诞节快到了,我们向所有人祈求上帝......”

and I'm supposed to get 'âÂÂ¥' as the heart symbol from the service. 我应该把'â'¥'作为服务中的心脏符号。

how to show this special character in unicode format, or in heart symbol as it is required? 如何以unicode格式显示此特殊字符,或者如果需要在心脏符号中显示?

which format is this text showing?? 这个格式是这个文本显示?? Is it HTML/XML format or Klingonese character, I don't have any idea about this. 是HTML / XML格式还是Klingonese字符,我对此一无所知。

How to show the heart sign using Html.fromHtml in android? 如何在android中使用Html.fromHtml显示心脏标志?


EDIT: From the service I may get different special characters like " ' " or "&" but what I'm getting is "’" instead of " ' ", "âÂÂ¥" instead of " ♥ " 编辑:从服务中我可能得到不同的特殊字符,如“'”或“&”,但我得到的是“—而不是“'”,“Ã¥”而不是“♥”

Is there any way to check all the text and show the correct special character in android? 有没有办法检查所有文本并在android中显示正确的特殊字符?


EDIT 2: Can anyone tell me how to show a heart symbol and apostrophe at their position from this string 编辑2:任何人都可以告诉我如何在这个字符串的位置显示心脏符号和撇号

String desc = "âÂÂ¥heart icon check, €™ apostrophe check";

i have already used all these procedures: 我已经使用了所有这些程序:

byte[] bytes = desc.getBytes("UTF-8");              
String s2 = new String(bytes, "UTF-8"); // Charset with which bytes were encoded
txtv.setText(s2);

final String s2 = new String(desc.getBytes(), "UTF-8");
txtv.setText(s2);

String s2 = URLDecoder.decode(desc, "UTF-8");
txtv.setText(s2);

byte[] data = desc.getBytes("UTF-8");
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
byte[] data1 = Base64.decode(base64, Base64.DEFAULT);
String text = new String(data1, "UTF-8");
txtv.setText(text);

but none of them are working, how to show UTF-8 text format in its actual format 但它们都没有工作,如何以实际格式显示UTF-8文本格式

Thanks 谢谢

You maybe confused with Java Character & Android Character. 你可能会对Java Character和Android Character感到困惑。

let your cardsDataClass.getCarddesc() returns: 让你的cardsDataClass.getCarddesc()返回:

"\❤All is changing soon, Christmas coming and we pray to God for all to..." “\\ u2764很快就会改变,圣诞节快到了,我们向所有人祈求上帝......”

and the heart should be shown just fine. 心脏应该显示得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM