How can I put utf-16 characters in Android string resource? How can I put utf-16 characters in Android string resource? xml xml

How can I put utf-16 characters in Android string resource?


But the strings.xml resource file is UTF8

If it's UTF-8 encoded, you can put your emojis directly. But then you risk that your editor or another piece of software destroys them.

If you are putting them in XML, you can try using XML entities: 😀, I'm not sure how well Android supports them though.

You can also use surrogate pairs: convert the emoji to UTF-16 and use standard \u escape. You can for example check out this page, it even tells you how to create a string litaral in Java: http://www.fileformat.info/info/unicode/char/1F600/index.htm

😜 → U+1F600 → "\uD83D\uDE00"


The easiest way it just copying and pasting the emoji, it works from Android Studio 3.0 and newer


Add the resource like follows:

<string name="string_title">This is a emoji example <U+1F642></string>

In Android Studio 3.0 you can copy and paste an emoji:

Emoji

And here how it looks:

Emoji