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.
延伸文章資訊
- 1How to set emoji by unicode in a textview? - py4u
??? unicode = U+1F60A String emoji = getEmojiByUnicode(unicode) String text = "So ...
- 2关于android:如何在TextView中通过Unicode设置表情符号?
How to set emoji by unicode in a textview?嗨,我想做以下事情:[cc]??? unicode = U+1F60AString emoji = getEm...
- 3How to access and use emoji on Android
- 4How to set emoji by unicode in a textview? - Stack Overflow
How to set emoji by unicode in a textview? android unicode textview encode emoji. Hi I'd like to ...
- 5Display emoji/emotion icon in Android TextView | Newbedev
Why do you want to embed the protected Apple emoji images in your application at all? The Unicode...