![](/img/trans.png)
[英]how to show html.fromhtml text in recyclerview from database android
[英]How to show heart sign in android using Html.fromHtml
在我的應用程序中,我從服務器獲取一些數據,數據可能包含一些像心臟等的unicode字符。
現在,我可以使用unicode格式顯示黑心符號
String str = "\u2764";//unicode character for black heart
TextView txtv = (TextView)findViewById(R.id.txtv);
txtv.setText(txtv.getText()+str);
但我正在設置這樣的文字:
holder.txt_cardDesc.setText(Html.fromHtml(cardsDataClass.getCarddesc()));
cardsDataClass.getCarddesc()返回“â¥所有即將改變,聖誕節快到了,我們向所有人祈求上帝......”
我應該把'â'¥'作為服務中的心臟符號。
如何以unicode格式顯示此特殊字符,或者如果需要在心臟符號中顯示?
這個格式是這個文本顯示?? 是HTML / XML格式還是Klingonese字符,我對此一無所知。
如何在android中使用Html.fromHtml顯示心臟標志?
編輯:從服務中我可能得到不同的特殊字符,如“'”或“&”,但我得到的是“—而不是“'”,“Ã¥”而不是“♥”
有沒有辦法檢查所有文本並在android中顯示正確的特殊字符?
編輯2:任何人都可以告訴我如何在這個字符串的位置顯示心臟符號和撇號
String desc = "âÂÂ¥heart icon check, €™ apostrophe check";
我已經使用了所有這些程序:
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);
但它們都沒有工作,如何以實際格式顯示UTF-8文本格式
謝謝
你可能會對Java Character和Android Character感到困惑。
讓你的cardsDataClass.getCarddesc()返回:
“\\ u2764很快就會改變,聖誕節快到了,我們向所有人祈求上帝......”
心臟應該顯示得很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.