简体   繁体   English

Android 表情符号渲染问题

[英]Android issue with rendering emoji

I have textfield that I am setting text string and observing strange issue我有文本字段,我正在设置文本字符串并观察到奇怪的问题

If the string is "" which is codepoints 128591 1f64f I see this image1如果字符串是 "" 这是代码点 128591 1f64f 我看到这个 image1

But if the string is "" which is basically 2 code points with values 128591 128591, I see this image但是如果字符串是“”,它基本上是 2 个代码点,值为 128591 128591,我看到这个图像

在此处输入图像描述

Is there something special I need to do in order for the first emoji to get rendered correctly in a textView?为了让第一个表情符号在 textView 中正确呈现,我需要做些什么特别的事情吗?

The emoji in question is - https://www.unicodepedia.com/unicode/emoticons/1f64f/person-with-folded-hands/有问题的表情符号是 - https://www.unicodepedia.com/unicode/emoticons/1f64f/person-with-folded-hands/

I am using appCompat 1.4.1 and I am use AppCompatTextView to render text.我正在使用 appCompat 1.4.1 并且我正在使用 AppCompatTextView 来呈现文本。

Above issue was because I was setting wrong length on spannable string that had emoji.上述问题是因为我在带有表情符号的可跨越字符串上设置了错误的长度。

I distilled the code down to following我将代码提炼为以下内容

val spannableText = SpannableString("x\uD83D\uDE4F")
val urlSpan = URLSpan("https://www.google.com/")
spannableText.setSpan(
    urlSpan,
    1,
    2,
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
) 

That produces output that looks like this:生成的 output 如下所示:

在此处输入图像描述

In above example if I set start and end position of the span "correctly" over the entire emoji things look correct.在上面的示例中,如果我在整个表情符号上“正确”设置跨度的开始和结束 position,那么事情看起来是正确的。

val spannableText = SpannableString("x\uD83D\uDE4F")
val urlSpan = URLSpan("https://www.google.com/")
spannableText.setSpan(
    urlSpan,
    1,
    3,
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

I have code that builds complex spannable, so I got computation of span length wrong when there is codepoint/emoji in the string.我有构建复杂 spannable 的代码,所以当字符串中有代码点/表情符号时,我的跨度长度计算错误。

I "distilled" my issue above.我在上面“提炼”了我的问题。 Posting an update here, in case someone runs into this in the future.在这里发布更新,以防将来有人遇到这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM