1
头图

Emoji has become ubiquitous. Since its release, emoji has become an indispensable part of our language. Its vivid and effective expressive power has brought about changes in language and writing. You might not think that even banking apps, fitness apps, or food delivery apps should support emoji. Emoji has now spread throughout messaging applications such as SMS, and has become a part of our language. If your app contains a text view, then it should support emoji. As for the reason, let me talk about it. 🥳

encountered by 161ca99dbb7665😖

If your app does not handle emojis accordingly, earlier versions of Android may not know how to display them. In most cases, only a blank square is displayed, which we call "tofu". In an application that does not handle emoji correctly, a "tofu block" will be displayed where the emoji should be displayed, which may cause confusion to users. For example, if the user adds a 🐶 emoticon to EditText in the task list of the TODO application, when the user sees "tofu" appearing on the screen without displaying the entered 🐶 emoticon, the user will think that the application has a bug.

In order to make emoji more interesting, in many cases, one emoji is composed of other emoji. For example, 💪🏾 is a combination of 💪 and 🟫.

If you input muscle expressions and the app displays arms and color squares, it will not only confuse the user, but also inaccurate the expression of different skin color styles, thereby reducing the user experience of the app.

With the development of language, emoji is constantly evolving. Every year, new emojis are added in the form of Unicode to new Android releases, but unfortunately, there is no way to add new emoji fonts to previous versions of Android S.

solution

emoji2 The library has been integrated into AppCompat 1.4, which means you only need to upgrade to AppCompat 1.4 to display popular emojis on API 19 and higher. All TextView in AppCompat are supported by default, because we have added automatic configuration, so it can configure itself to load the correct emoji font. If necessary, you can turn off this feature for a specific TextView in XML or code.

Let's take a look at the difference in emoji display between AppCompat 1.3 and AppCompat 1.4.


Simply put, the graphical emoji is actually just a picture displayed in the text 🖼️. It is represented by a Unicode code point, like the letter'e', but Unicode stipulates: When displaying the code point, the emoji picture should be displayed instead of the letter'e'. This image is only a png font file (for more information, please see our for Android to create emoji font ). ', but in fact the function of the font is very powerful, which can include bitmap, png, svg, and even complete programs-someone has implemented a 16aca99dbb7734 game 🤯 in the font.

When adding a new emoji in Unicode, the new emoji needs to add the new glyph or printable characters to the emoji font-and then update the corresponding table, the font will know which code point to display this glyph.

When inputting a string to the platform, EmojiCompat.process needs to convert it to include EmojiSpan . It will tell the Android system not to display this part as a string. EmojiSpan knows how to display emoji.

EmojiCompat.process ) will traverse the string and find all emojis, and add EmojiSpan to each emoji. EmojiSpan will tell Android not to display it in the form of a string, but to call the draw method to display it. EmojiCompat.process uses a dictionary tree to find all substrings to match a known emoji.

The dictionary tree is a very interesting data structure, which is very suitable for efficiently looking up words (or emoji) in the dictionary. EmojiCompat will traverse the string and check each code point against the dictionary tree. Once it finds the complete emoji in the dictionary tree, it checks if the platform is not clear on how to display the emoji and adds EmojiSpan. You can understand that EmojiCompat uses a dictionary to find emoji in a string, and the definition of the corresponding dictionary content is how to use EmojiSpan to display the desired emoji.

Now that we know how EmojiCompat gets emoji, let's talk about how to display the string "Hi".

A character string is a set of code points, which use numbers to represent glyphs, such as the letter'm' or the number '1'. Emoji also have corresponding code points-you can Emojipedia waved emoji we want to display now.

Finally, the draw function will be called, and then the emoji in the font file will be drawn directly, and include the effect you want-your string! 🥳🥳🥳

last

Emoji is more than just fun, it has become an integral part of our language. If you are ready to provide users with the best experience supporting popular emoji, please use AppCompat 1.4.

Keep going, keep using emoji~ 🥳 🦄

For more information about the latest Play policy of emoji, please refer to

Welcome Click here submit feedback to us, or share your favorite content found problems. Your feedback is very important to us, thank you for your support!


Android开发者
404 声望2k 粉丝

Android 最新开发技术更新,包括 Kotlin、Android Studio、Jetpack 和 Android 最新系统技术特性分享。更多内容,请关注 官方 Android 开发者文档。