Emoji has been everywhere. Since its release, Emoji has become an indispensable part of our language, and its vivid and effective expression has brought about changes in language and words. You might not think that banking apps, fitness apps or food delivery apps should support emoji. Emojis are now ubiquitous in messaging apps, part of our language. If your app has a text view, it should support emoji, and I’ll explain why. 🥳
Problems encountered 😖
Older versions of Android may not know how to display emojis if your application does not handle them accordingly. In most cases, only a blank square is displayed, which we call “tofu”. In apps that don’t handle emoji properly, a “bean curd” appears where the emoji should be displayed, which can cause confusion for users. For example, if a user adds an 🐶 emoji to the EditText in the TODO app’s task list and sees the word “tofu” appear on the screen instead of the typed 🐶 emoji, the user will think the app is buggy.
To make emoji more interesting, in many cases, one emoji is made up of several other emoji. For example, 💪🏾 is a combination of 💪 and 🟫.
If you enter a muscular expression and the app shows arms and color squares, not only will it confuse the user, but it will also inaccurately describe different skin tones and styles, reducing the user experience of the app.
As languages evolve, so do emojis. Each year new emoji are added to the new Android distribution in Unicode form, but unfortunately there is no way to add the new emoji font to previous versions of Android S.
The solution
The Emoji2 library is already integrated with AppCompat 1.4, which means you can simply upgrade to AppCompat 1.4 to display popular emojis on API 19 and above. All textViews in AppCompat are supported by default, because we added automatic configuration, so it can configure itself to load the correct emoji font. You can turn this off for a particular TextView in XML or code if you want.
Let’s take a look at how emoji displays differ between AppCompat 1.3 and AppCompat 1.4.
Simply put, a graphical emoji is really just a picture displayed in text 🖼️. It is represented by Unicode code points, like the letter ‘e’, but Unicode dictates that when code points are displayed, emoji images should be displayed instead of the letter ‘E’. This image is just a PNG in a font file (see our Emoji fonts for Android for more). Often you might think of font content as a stroke definition of the letter ‘e’, but in fact fonts are very powerful and can include bitmaps, PNG, SVG, and even full programs — someone implemented a game in fonts 🤯.
When a new emoji is added in Unicode, the new emoji needs to add the new glyphs or printable characters to the emoji font — and then update the corresponding table so that the font knows by which code point to display the glyphs.
When a string is entered into the platform, emojicompat.Process needs to convert it to include EmojiSpan, which tells the Android system not to display that part as a string. EmojiSpan knows how to display emojis.
Emojicompat. process iterates through the string and finds all emojis, adding an EmojiSpan to each emoji. EmojiSpan tells Android not to display it as a string, but to call the draw method instead. Emojicompat. process uses the dictionary tree to find all the substrings to match a known emoji.
Dictionary trees are interesting data structures that are perfect for efficiently looking up words (or emoji) in dictionaries. EmojiCompat iterates through the string, checking each code point against the dictionary tree. Once it finds the full emoji in the dictionary tree, it checks if the platform doesn’t know how to display the emoji and adds EmojiSpan. You can understand that EmojiCompat is to use the dictionary to find emoji in the string, and the definition of the corresponding dictionary content is how to use EmojiSpan to display the required emoji.
Now that we know how EmojiCompat gets emojis, let’s talk about how to display the string “Hi”.
A string is a set of code points that represent glyphs by numbers, such as the letter ‘m’ or the number ‘1’. Emoji also have code points — you can find them at Emojipedia, including the waving Emoji we’re showing right now.
Finally, the draw function is called and draws the emoji directly from the font file, including the desired effect — your string! 🥳 🥳 🥳
The last
Emoji isn’t just fun, it has become an integral part of our language. If you’re ready to give users the best possible experience with popular emoji support, use AppCompat 1.4.
Move on and keep using emoji ~ 🥳 🦄
For more information on the latest Play policy for emoji, see.
Please click here to submit your feedback to us, or share your favorite content or questions. Your feedback is very important to us, thank you for your support!