Display emoji/emotion icon in Android TextView | Newbedev

文章推薦指數: 80 %
投票人數:10人

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(){{ add('\ue415'); add('\ue056'); ... }} YoucouldalsodothiswitharegexbutIbelievetheabovewouldrunfaster. Tags:JavaAndroidUnicodeTextviewEmojiRelatedHowdoIinstall2differentversionsofjavaonthesamemachinefromEPELHowtoHandleSuddenBurstinNewHTTPSConnections?Whyisn'tthereaopenjdk-8-jdkpackageondebiananymore?PleasehelpinterpretOOM-KillerSupermicroIPMIViewKVMConsoledoesnotworkatallJavaissuedrivingmecrazyCannotinstallopenjdk-8-jre-headlessonDebianJessieTheoptionto"LaunchslaveagentsviaJavaWebStart"ismissingfromnewnodeconfiguration,howcanIaddittotheoptionsmenu?Howtogeneratenew,2048-bitDiffie-HellmanparameterswithJavakeytool?HowcanIupgradetoJava1.8onanAmazonLinuxServer?PandashowtofindcolumncontainsacertainvalueRecommendedwaytoinstallmultiplePythonversionsonUbuntu20.04BuildsuperfastwebscraperwithPythonx100thanBeautifulSoup



請為這篇文章評分?