【问题标题】:How to render emoji in a Textview in android?如何在 android 的 Textview 中呈现表情符号?
【发布时间】:2016-06-17 19:02:44
【问题描述】:

我正在开发一个正在实现表情符号的聊天应用程序,但我在适配器中有一个问题,如何在 Textview 中呈现表情符号。

emocationGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            emoDrawables.get(position).setBounds(0, 0, emoDrawables.get(position).getIntrinsicWidth(),
            emoDrawables.get(position).getIntrinsicHeight());

            int selectionCursor = chatMsgEtd.getSelectionStart();
            chatMsgEtd.getText().insert(selectionCursor, ".");
            selectionCursor = chatMsgEtd.getSelectionStart();

            SpannableStringBuilder builder = new SpannableStringBuilder(chatMsgEtd.getText());
            builder.setSpan(new ImageSpan(emoDrawables.get(position)), selectionCursor - ".".length(),
                    selectionCursor, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            chatMsgEtd.setText(builder);
            chatMsgEtd.setSelection(selectionCursor);
        }
});

适配器

chatMsgTxt.setText(chats.get(position).getMessage());

所以在适配器中 getMessage 是聊天消息,但这里如何用消息呈现表情符号。

请浏览我的帖子并建议我一些解决方案。

【问题讨论】:

标签: android chat render emoji


【解决方案1】:

您可以在TextView 上设置一个跨度,很可能您想扩展DynamicDrawableSpan 并将图像源到该跨度中。如果您的目标是渲染 iOS 表情符号而不是默认的 android 表情符号,您应该使用 https://github.com/instachat/emoji-libraryhttps://github.com/rockerhieu/emojicon 之类的库

【讨论】:

    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2016-04-05
    • 2014-09-28
    • 1970-01-01
    相关资源
    最近更新 更多