How to set emoji by unicode in a textview? - Stack Overflow

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

How to set emoji by unicode in a textview? android unicode textview encode emoji. Hi I'd like to do the following: ??? unicode = U+ ... Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore Howtosetemojibyunicodeinatextview? AskQuestion Asked 7yearsago Active 2monthsago Viewed 85ktimes 100 44 HiI'dliketodothefollowing: ???unicode=U+1F60A Stringemoji=getEmojiByUnicode(unicode) Stringtext="Sohappy" textview.setText(text+emoji); togetthisinmytextview: Sohappy😊 HowcanIimplementgetEmojiByUnicode(unicode)? Whattypeshouldtheunicodevariablebe?(String,char,int?) PleasenotethatIdoNOTwanttouseDrawables! androidunicodetextviewencodeemoji Share Improvethisquestion Follow editedMay22'19at16:29 ADroid 9591111silverbadges2121bronzebadges askedNov12'14at18:19 GilbertGiesbertGilbertGiesbert 2,98833goldbadges1212silverbadges1010bronzebadges 0 Addacomment  |  6Answers 6 Active Oldest Votes 199 Foundasolution: InmyunicodeIreplaced'U+'by'0x' Example:replace'U+1F60A'by'0x1F60A' ThiswayIgotan'int'like intunicode=0x1F60A; Whichcanbeusedwith publicStringgetEmojiByUnicode(intunicode){ returnnewString(Character.toChars(unicode)); } SoTextviewdisplays😊withoutDrawable Tryitwithhttp://apps.timwhitlock.info/emoji/tables/unicode Share Improvethisanswer Follow editedDec27'16at8:41 Amos 1,47111goldbadge2020silverbadges3333bronzebadges answeredNov12'14at18:40 GilbertGiesbertGilbertGiesbert 2,98833goldbadges1212silverbadges1010bronzebadges 7 3 workson5.1buton4.4.4igeta?formyemojistring – filthy_wizard Jul4'16at12:55 23 Isitpossibletodothisinstrings.xmlfile? – Spektakulatius Sep13'16at12:23 @user1232726,Thiswilldependontheuser'sphoneincludingtheemojibeingused. – Suragch Jan17'17at3:41 3 Unfortunatelyitdoesn'tworkwith32bitUnicode,likeU+1F1EFU+1F1F2.Thisvalueisoutsidetheintegerboundaries. – Chris-Jr Feb4'18at5:46 1 NOte:ForKotlin>fungetEmoji(unicode:Int):String{returnString(Character.toChars(unicode))} – BipinBharti Aug30'18at7:21  |  Show2morecomments 50 YoucandirectlyuseEmojisinstringresourcesbyusingthedecimalcodelikethis: 😊 forexample: Iamhappy😊> Share Improvethisanswer Follow editedMay14'19at16:00 VadimKotov 7,41688goldbadges4545silverbadges6060bronzebadges answeredMay25'18at8:21 P1xelfehlerP1xelfehler 96266silverbadges1818bronzebadges 4 14 Thisisagoodanswer;tofindthedecimalcodeofanemoji,youcanusesomethinglikequackit.com/character_sets/emoji – Adinia May30'18at14:07 1 idon'tfindthexnecessary – hmac Oct4'18at20:27 3 Errorwhilebuild:Characterreference" – Dr.aNdRO Nov12'18at5:36 @hmacI'verolledbacktheanswer,removedmentionsofx – VadimKotov May14'19at16:01 Addacomment  |  6 Note:ForKotlin fungetEmoji(unicode:Int):String{ returnString(Character.toChars(unicode)) } Share Improvethisanswer Follow editedMay14'19at15:54 VadimKotov 7,41688goldbadges4545silverbadges6060bronzebadges answeredJul18'18at13:10 BipinBhartiBipinBharti 92022goldbadges1212silverbadges2525bronzebadges Addacomment  |  0 IthinkIfoundthemoststraightforwardsolution.Inmycase,Iwantedtoaddafire(🔥)emojitooneofthechipsinachipgroup.IsimplywenttotheEmojipediaFireEntry1,clickedonthecopybuttonjustbelowtheemojimeaning,andliterallyjustpasteditintomyKotlincode.Hereisacodesnippetofhowitlookedlikeafterpasting. valchip=Chip(context) chip.text="\uD83D\uDD25New" HereishowthecodelookslikeonceIrunitonmydevice.Iincludedtheotherchipsaswell😉; PS:IranthisonthelatestversionofAndroidStudio(ArcticFoxv.2020.3.1).Resultsmaydifferwitholderversions. Footnote EmojipediaisafreeencyclopediathatlistsandprovidesmeaningsforalltheemojisapprovedundertheUnicodestandard.Youcanalwaysheadoutthereforinsightfulemojimeaningsandforotheremojineeds. Share Improvethisanswer Follow answeredAug5at6:33 KennethMurerwaKennethMurerwa 37144silverbadges1010bronzebadges Addacomment  |  0 allofthecredittoKennethMurerwa,whoseanswersolvedmyproblem.justchiminginthatjustcopyandpastewhatyougetfromthe'copy'buttonathttps://emojipedia.orgbetweengoodoldquotationmarks.Yeah,it'sanoobpointbuthey,we'reallnoobsatthebeggining😂 valemoji="\uD83D\uDE00\uD83D\uDC4C" andthenyoucanaddittowhateverstringyouneed.Itrendersonthephonescreenfine,thoughitwon'tshowupinaprintln println("👌") Share Improvethisanswer Follow answeredSep1at1:34 TomasBoncompteTomasBoncompte 1 Addacomment  |  0 Youcandoasbelow: Unicode:uni-1F4A1 FYI,IamusingKotlin. Createutilityfunctionasbelow: privatefungetEmojiByUnicode(reactionCode:String):String{ valcode=reactionCode.substring(4).toInt(16) returnString(Character.toChars(code)) } Wheresubstring(4)willbediscardeduni-these3charactersandyouhave1F4A1. SetEmojiintoTextView:(IamusingViewBindinginmyProject) mViewBinding.textViewEmoji.text=getEmojiByUnicode(data.Reaction) Formoredetails:Integer.parseInt("0x1F60A")endswithNumberformatException Share Improvethisanswer Follow editedSep1at12:11 answeredSep1at12:05 ParthPatelParthPatel 93611goldbadge99silverbadges2626bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedandroidunicodetextviewencodeemojioraskyourownquestion. TheOverflowBlog Whoownsthisoutage?BuildingintelligentescalationchainsformodernSRE Podcast395:Whoisbuildingcloudsfortheindependentdeveloper? FeaturedonMeta Nowlive:Afullyresponsiveprofile Reducingtheweightofourfooter TwoBornottwoB-Farewell,BoltClockandBhargav! Linked 10 HowtoDisplayEmoticons/EmojiinSnackbarorToast/Textview 2 Putemojicodeinastring 2 AddemojitoAndroidkeyboard 2 Display\u00F0\u009F\u0098\u0098stringtoemojiinandroidtextview? 3 CantDisplayEmojisFromServerintextviewAndroid 0 Androidemojiissue(convert"\uD83D\uDE04"to0x1F604) 2 AndroidYesNoButtonemoji -1 AddingmultiplesmilesinTextViewusingImageSpan 2 AndroidACTION_SENDwithspecialunicodecharacters 0 HowtoaddemojisupportinappforpostingcommentsinAndroid? Seemorelinkedquestions Related 2207 HowdoIcentertexthorizontallyandverticallyinaTextView? 366 Unicode(UTF-8)readingandwritingtofilesinPython 623 Whatisthebestwaytoremoveaccents(normalize)inaPythonunicodestring? 4135 Howdoyouclose/hidetheAndroidsoftkeyboardprogrammatically? 837 HowtodisplayHTMLinTextView? 1092 HowtomakelinksinaTextViewclickable 918 HowtosetTextViewtextStylesuchasbold,italic 1092 Whatdoesthe'b'characterdoinfrontofastringliteral? 567 HowtohideunderbarinEditText 1391 WhyisexecutingJavacodeincommentswithcertainUnicodecharactersallowed? HotNetworkQuestions ConvertRegextoMask WhyarelegaldecisionsintheUSsopoliticized? Embeddingtorsorsofellipticcurvesintoprojectivespace Propertranslationfor"artissubtraction" RuyLopez-whydoesBlacknottakee4? DemerzelandtheLawsofRobotics IdentifyingMotherboardandCPU Isitagoodideatomaketheactionsofmyantagonistreasonable? WhydoesHebrews3:1callJesusanapostle? Mini-dashasageneralbonusaction:whatvaluewouldbebalanced? WhydidAtarifloppiesrunat288RPM? Whatdoes"Thebargaintotheletter"mean? WhyisReccepTayipErdoğanallowingtheTurkishLiratoplunge? Meaningof"ruinsomethingforsomeone" WhyistheSecondAmendmentstructureddifferentlyfromallotheramendments? Viewsversusafunctionforgettingthetoprecordsofatable? Couldsiliconbasedlifeformseatcarbonbasedfood Isitoktofeedmycatonechickenliverdaily? howtorecursivelyremoveembeddedcarriagereturninfilenames Usinga2TBSSDona2016MacBookPro Whydidn'ttheEnterprise-DsendaprobetolookforPicard? Whatpotentialdifferenceorcurrentwouldkillaperson? SinglechippowergoodIC? AreJapaneseprincessesandprincesreferredtobyadifferentwordinJapanesethanprincessesandprincesoutsideofJapan? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?