Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set emoji by unicode in a textview?

Hi I'd like to do the following:

??? unicode = U+1F60A String emoji = getEmojiByUnicode(unicode) String text = "So happy " textview.setText(text + emoji); 

to get this in my textview:

So happy 😊

How can I implement getEmojiByUnicode(unicode)?

What type should the unicode variable be? (String, char, int?)

Please note that I do NOT want to use Drawables!

like image 804
Gilbert Giesbert Avatar asked Nov 12 '14 18:11

Gilbert Giesbert


People also ask

Can Unicode represent Emojis?

Unicode provides a number of emoji resources which provides more information about emoji. In particular, Unicode Emoji TR #51 outlines many details of the entire emoji set. For questions about new emoji proposals or why a certain emoji does not exist, please see the Emoji Submission FAQ.

Does UTF 8 include emoji?

Emojis look like images, or icons, but they are not. They are letters (characters) from the UTF-8 (Unicode) character set.


2 Answers

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

like image 184
Gilbert Giesbert Avatar answered Oct 16 '22 17:10

Gilbert Giesbert


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

😊 

for example:

<string name="emoji">I am happy &#128522;</> 
like image 22
P1xelfehler Avatar answered Oct 16 '22 17:10

P1xelfehler