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!
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 😊</>
Bipin Bharti
Note: For Kotlin
fun getEmoji(unicode: Int): String {
return String(Character.toChars(unicode))
}
来源:https://stackoverflow.com/questions/26893796/how-to-set-emoji-by-unicode-in-a-textview