How to set emoji by unicode in a textview?

Solution 1:

Found a solution:

In my unicode I replaced 'U+' by '0x'

Example: replace 'U+1F60A' by '0x1F60A'

This way I got an 'int' like

int unicode = 0x1F60A;

Which can be used with

public String getEmojiByUnicode(int unicode){
    return new String(Character.toChars(unicode));
}

So Textview displays 😊 without Drawable

Try it with http://apps.timwhitlock.info/emoji/tables/unicode

Solution 2:

You can directly use Emojis in string resources by using the decimal code like this:

😊

for example:

<string name="emoji">I am happy &#128522;</>

Solution 3:

Note: For Kotlin

fun getEmoji(unicode: Int): String {
    return String(Character.toChars(unicode))
}

Solution 4:

I think I found the most straightforward solution. In my case, I wanted to add a fire (🔥) emoji to one of the chips in a chip group. I simply went to the Emojipedia Fire Entry1, clicked on the copy button just below the emoji meaning, and literally just pasted it into my Kotlin code. Here is a code snippet of how it looked like after pasting.

val chip = Chip(context)
chip.text = "\uD83D\uDD25 New"

Here is how the code looks like once I run it on my device. I included the other chips as well 😉;

An image sample of how the chip looks like in the device

PS: I ran this on the latest version of Android Studio (Arctic Fox v. 2020.3.1). Results may differ with older versions.

Footnote

  1. Emojipedia is a free encyclopedia that lists and provides meanings for all the emojis approved under the Unicode standard. You can always head out there for insightful emoji meanings and for other emoji needs.