How to set emoji by unicode in a textview?

≡放荡痞女 提交于 2019-11-26 14:10:54
Gilbert Giesbert

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

P1xelfehler

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

😊

for example:

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

Note: For Kotlin

fun getEmoji(unicode: Int): String {
    return String(Character.toChars(unicode))
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!