Display emoji/emotion icon in Android TextView | Newbedev
文章推薦指數: 80 %
Why do you want to embed the protected Apple emoji images in your application at all? The Unicode standard includes 722 emoji that can be displayed by ...
MenuNEWBEDEVPythonJavascriptLinuxCheatsheetContactNEWBEDEVDisplayemoji/emotioniconinAndroidTextViewWhydoyouwanttoembedtheprotectedAppleemojiimagesinyourapplicationatall?
TheUnicodestandardincludes722emojithatcanbedisplayedbyAndroid'sdefaultfontjustbyenteringtheUnicodecharsintoanEditTextfieldorTextView.
Youcan,inaddition,usethefollowinglibrary(infolder"Java")toautomaticallyconvertpopularemoticonslike:-)tothecorrespondingUnicodeemoji:
https://github.com/delight-im/Emoji
Here,Pleasegothroughbelowsolution:
Problem:InsideTextViewinsteadofEmoji,String\ue415\ue056\ue057isshowing.
Rootcause:Injavaorandroid,programmaticallystringrepresentationofEmoji'syouwillgetas\\ue415\\ue056\\ue057.ButwhenyoutrytoprintsameStringinconsoleorLogCatthenescapecharacterisremovedandyouwillgetstringas\ue415\ue056\ue057becauseofwhichrootcauseofthisissueisnotdetectable.
Solution:Tosolvethisissue,weneedtohandleescapecharacter.Ihavecreatedbelowmethodwhichsolvethisproblem.
publicstaticStringgetEmojiFromString(StringemojiString){
if(!emojiString.contains("\\u")){
returnemojiString;
}
StringemojiEncodedString="";
intposition=emojiString.indexOf("\\u");
while(position!=-1){
if(position!=0){
emojiEncodedString+=emojiString.substring(0,position);
}
Stringtoken=emojiString.substring(position+2,position+6);
emojiString=emojiString.substring(position+6);
emojiEncodedString+=(char)Integer.parseInt(token,16);
position=emojiString.indexOf("\\u");
}
emojiEncodedString+=emojiString;
returnemojiEncodedString;
}
Itworksfineifyouconvertthestringtoachararrayandcheckeachchar,suchas:
StringBuildersb=newStringBuilder();
for(charcurr:str.toCharArray()){
sb.append((SUPPORTED_EMOJI_SET.contains(curr))?convertCharToImgTag(curr):curr);
}
whereSUPPORTED_EMOJI_SETisjustasetofchars,forexample:
newHashSet
延伸文章資訊
- 1TextDrawable to display emojis and Unicode characters in ...
TextDrawable to display emojis and Unicode characters in Android ... Aligning the text to the tex...
- 2how set emoji by unicode in a textview? - SemicolonWorld
??? unicode = U+1F60A String emoji ...
- 3How to set emoji by unicode in a textview? | Newbedev
So Textview displays without Drawable. Try it with http://apps.timwhitlock.info/emoji/tables/unic...
- 4How to set emoji by unicode in a textview? - py4u
??? unicode = U+1F60A String emoji = getEmojiByUnicode(unicode) String text = "So ...
- 5Emoji Compatibility | Android Developers
It also updates the necessary emoji metadata that the EmojiCompat support library needs to keep u...