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

倾然丶 夕夏残阳落幕 提交于 2019-11-30 06:48:50

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:

And here how it looks:

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