TextDrawable to display emojis and Unicode characters in ...
文章推薦指數: 80 %
TextDrawable to display emojis and Unicode characters in Android ... Aligning the text to the text in the TextView/EditText would be tricky. GetstartedOpeninappAliMuzaffarSigninGetstarted3.7KFollowersAboutGetstartedOpeninappTextDrawabletodisplayemojisandUnicodecharactersinAndroidThebestwaytoaddemojisandgraphicstoyourappwithoutbundlinggraphicsistouseUnicodecharacters.Unfortunately,settingtheseasdrawablescanberathertricky.AliMuzaffarMar5,2016·3minreadLastweek,ItalkedwithafewpeopleaboutthepossibilityofusingTextDrawabletoaddafixedprefixtoanEditText.Thereareunfortunatelyafewdifferentchallenges.Whichmadethisdifficultforme:CannotbedonewithXML’s(thereissomeliteratureaboutit,butafewobjectsIneededwereprivateandIcouldn’tgetholdofthem.Sincewecan’tcreatethisinXMLorsetitasacompounddrawableorbackgroundinXML,wegetnopreviewintheeditor.Drawablewouldhavetobepassedapaintobject.AligningthetexttothetextintheTextView/EditTextwouldbetricky.Well,thiswasn'tashardasIthoughtitwouldhavebeen.Asamatteroffactitworkedoutrathernicely.Notonlycanyouuseitasacompounddrawable,youcansetitasabackgroundaswell.I'vealsoimplementtheabilitytoaskittoresizethetextdrawntofillaTextView’sbackground.WhydoIneedaTextDrawablePossibleusecasesforanEditTextcanbe:ShowaprefixonEditTextthatcan’tbeeditable.Showacharactercounteronrightorleftdrawablesposition.Showindicationusinguni-codecharactersthatinputis,short,long,correctorincorrectinanEditText.UsetotoshowanellipsisonasinglelineEditTextifthetextislongasanindicatorthatthereissomethingoffscreen.Ifyouwanttoknowmoreaboutthis,pingmeandI’llgiveyouanexample.MostoftheaboveispossiblewithanimagesorbystackingViewstogether,thisishopefullyacleanersolutionifUnicodecharactersandtextaregoodenough(andwhywon’tthisbe☺).ShowmeademoItsworthpointingoutthatsincethedrawablereservesitsspacewhensetasacompounddrawable(left,right,toporbottom)thatchangingthetextinthisscenariodoesn'tworkasexpected.Justlookatthedemobelow.The+61andthe★thatyouseeintheEditTextaredrawntherewiththeTextDrawable.The☺thatyouseeisalsodonewithaTextDrawable,setasthebackgroundofaTextView,itisthenbeingupdatedusingacountdowntimer.Asyoucansee,itcanresizethetexttoensurethatitfitsintheView’swidthwhichis200dp.ThecodeThecodeisongist.FinallyInordertobuildgreatAndroidapps,readmoreofmyarticles.Yay!youmadeittotheend!Weshouldhangout!feelfreetofollowmeonMedium,LinkedIn,Google+orTwitter.AliMuzaffarAsoftwareengineer,anAndroid,andarayofhopeforyourdarkestcode.ResidinginSydney.Follow70270 702AndroidAppDevelopmentAndroidAndroidDevMorefromAliMuzaffarFollowAsoftwareengineer,anAndroid,andarayofhopeforyourdarkestcode.ResidinginSydney.
延伸文章資訊
- 1TextDrawable to display emojis and Unicode characters in ...
TextDrawable to display emojis and Unicode characters in Android ... Aligning the text to the tex...
- 2android - How to set emoji by unicode in a textview? - OStack.cn
??? unicode = U+1F60A String emoji = getEmojiByUnicode(unicode) String text = "So happy " textvie...
- 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...
- 4FAQ - Emoji & Pictographs - Unicode
- 5How to Input Unicode - Xah Lee